From abe12ce857c5978226b3d0549dceea2ab797df8a Mon Sep 17 00:00:00 2001 From: smiddlek Date: Thu, 19 Aug 2010 13:02:12 +0000 Subject: git-svn-id: http://pymox.googlecode.com/svn/trunk@56 b1010a0a-674b-0410-b734-77272b80c875 --- mox.py | 2 +- mox_test.py | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/mox.py b/mox.py index a4a4fb5..d6be02a 100755 --- a/mox.py +++ b/mox.py @@ -898,7 +898,7 @@ class MethodSignatureChecker(object): # correct, this will cause extra executions of the function. if inspect.ismethod(self._method): # The extra param accounts for the bound instance. - if len(params) == len(self._args) + 1: + if len(params) == len(self._required_args) + 1: expected = getattr(self._method, 'im_class', None) # Check if the param is an instance of the expected class, diff --git a/mox_test.py b/mox_test.py index bb684de..cdc3d55 100755 --- a/mox_test.py +++ b/mox_test.py @@ -574,13 +574,6 @@ class MockAnythingTest(unittest.TestCase): self.assertRaises(mox.UnexpectedMethodCallError, self.mock_object.OtherValidCall) -# def testReplayWithUnexpectedCell_BadSignatureWithTuple(self): -# self.mock_object.ValidCall(mox.In((1, 2, 3))) -# self.mock_object._Replay() -# self.assertRaises(mox.UnexpectedMethodCallError, -# self.mock_object.ValidCall, 4) - - def testVerifyWithCompleteReplay(self): """Verify should not raise an exception for a valid replay.""" self.mock_object.ValidCall() # setup method call @@ -1576,7 +1569,6 @@ class MoxTest(unittest.TestCase): self.assertEquals('foo', actual) def testStubOutMethod_CalledAsUnboundMethod_Subclass_Comparator(self): - print 'this test' self.mox.StubOutWithMock(mox_test_helper.TestClassFromAnotherModule, 'Value') mox_test_helper.TestClassFromAnotherModule.Value( mox.IsA(mox_test_helper.ChildClassFromAnotherModule)).AndReturn('foo') @@ -1589,6 +1581,18 @@ class MoxTest(unittest.TestCase): self.mox.UnsetStubs() self.assertEquals('foo', actual) + def testStubOuMethod_UnboundWithOptionalParams(self): + self.mox = mox.Mox() + self.mox.StubOutWithMock(TestClass, 'OptionalArgs') + TestClass.OptionalArgs(mox.IgnoreArg(), foo=2) + self.mox.ReplayAll() + + t = TestClass() + TestClass.OptionalArgs(t, foo=2) + + self.mox.VerifyAll() + self.mox.UnsetStubs() + def testStubOutMethod_CalledAsUnboundMethod_ActualInstance(self): instance = TestClass() self.mox.StubOutWithMock(TestClass, 'OtherValidCall') @@ -2044,6 +2048,9 @@ class TestClass: def OtherValidCall(self): pass + def OptionalArgs(self, foo=None): + pass + def ValidCallWithArgs(self, *args, **kwargs): pass -- cgit v1.2.1