What steps will reproduce the problem?
import unittest
import mox
class Foo(object):
def a(self, a, b):
pass
def b(self, a, b):
pass
class TestFoo(unittest.TestCase):
def setUp(self):
self.mox = mox.Mox()
def test_in_any_order_missing_calls(self):
a = self.mox.CreateMock(Foo)
a.a(a=1, b=2).InAnyOrder("foo")
a.a(a=1, b=2).InAnyOrder("foo")
a.b(a=1, b=2).InAnyOrder("foo")
self.mox.ReplayAll()
a.a(a=1, b=2)
self.mox.VerifyAll()
def test_in_any_order_bad_call(self):
a = self.mox.CreateMock(Foo)
a.a(a=1, b=2).InAnyOrder("foo")
a.a(a=1, b=2).InAnyOrder("foo")
a.b(a=1, b=2).InAnyOrder("foo")
self.mox.ReplayAll()
a.a(a=1, b=2)
a.a(a=2, b=2)
self.mox.VerifyAll()
What is the expected output? What do you see instead?
Output as following (running in nosetests):
======================================================================
FAIL: test_in_any_order_bad_call (foo.TestFoo)
----------------------------------------------------------------------
Traceback (most recent call last):
File ".../foo.py", line 46, in test_in_any_order_bad_call
a.a(a=2, b=2)
File ".../mox.py", line 983, in __call__
expected_method = self._VerifyMethodCall()
File ".../mox.py", line 1035, in _VerifyMethodCall
expected, method = expected.MethodCalled(self)
File ".../mox.py", line 1752, in MethodCalled
raise UnexpectedMethodCallError(mock_method, self)
UnexpectedMethodCallError: Unexpected method call. unexpected:-
expected:+
- Foo.a(a=2, b=2) -> None
+ <UnorderedGroup "foo">
======================================================================
FAIL: test_in_any_order_missing_calls (foo.TestFoo)
----------------------------------------------------------------------
Traceback (most recent call last):
File ".../foo.py", line 36, in test_in_any_order_missing_calls
self.mox.VerifyAll()
File ".../mox.py", line 284, in VerifyAll
mock_obj._Verify()
File ".../mox.py", line 504, in _Verify
raise ExpectedMethodCallsError(self._expected_calls_queue)
ExpectedMethodCallsError: Verify: Expected methods never called:
0. <UnorderedGroup "foo">
----------------------------------------------------------------------
The Problem with the above is that in the first case the unexpected method
call's expected method call is obscured by the UnorderedGroup
representation.
The problem in the second case is that it's not obvious which calls are
missing.
The following is from a patched version of pymox:
======================================================================
FAIL: test_in_any_order_bad_call (foo.TestFoo)
----------------------------------------------------------------------
Traceback (most recent call last):
File ".../foo.py", line 46, in test_in_any_order_bad_call
a.a(a=2, b=2)
File ".../mox.py", line 983, in __call__
expected_method = self._VerifyMethodCall()
File ".../mox.py", line 1035, in _VerifyMethodCall
expected, method = expected.MethodCalled(self)
File ".../mox.py", line 1756, in MethodCalled
raise UnexpectedMethodCallError(mock_method, self)
UnexpectedMethodCallError: Unexpected method call. unexpected:-
expected:+
+ UnorderedGroup "foo" pending calls:
- Foo.a(a=2, b=2) -> None
? ^
+ Foo.a(a=1, b=2) -> None
? ^ +
+ Foo.b(a=1, b=2) -> None
======================================================================
FAIL: test_in_any_order_missing_calls (foo.TestFoo)
----------------------------------------------------------------------
Traceback (most recent call last):
File ".../foo.py", line 36, in test_in_any_order_missing_calls
self.mox.VerifyAll()
File ".../mox.py", line 284, in VerifyAll
mock_obj._Verify()
File ".../mox.py", line 504, in _Verify
raise ExpectedMethodCallsError(self._expected_calls_queue)
ExpectedMethodCallsError: Verify: Expected methods never called:
0. UnorderedGroup "foo" pending calls:
Foo.a(a=1, b=2) -> None
Foo.b(a=1, b=2) -> None
----------------------------------------------------------------------
What version of the product are you using? On what operating system?
SVN trunk r47 (0.5.3 being the latest release prior)
Please provide any additional information below.
I've patched pymox to:
a) Remove spurious newlines in the difflib output from unexpected method
calls.
b) Display the pending method calls in an UnorderedGroup object via
__repr__.
Both changes are included in the attached patch.
Original issue reported on code.google.com by great...@gmail.com on 11 May 2010 at 6:29
Original issue reported on code.google.com by
great...@gmail.com
on 11 May 2010 at 6:29Attachments: