summaryrefslogtreecommitdiff
path: root/mox_test.py
diff options
context:
space:
mode:
authorsmiddlek <smiddlek@b1010a0a-674b-0410-b734-77272b80c875>2010-07-07 17:43:04 +0000
committersmiddlek <smiddlek@b1010a0a-674b-0410-b734-77272b80c875>2010-07-07 17:43:04 +0000
commitf8770adb29be14845b407494cc0e3e1b98ce75e3 (patch)
treeaded93a6aaeb8638d12c36664f195f6dbfd06c7e /mox_test.py
parent04786f376e2bebe44fc19422bbadaa3d68de2138 (diff)
downloadmox-f8770adb29be14845b407494cc0e3e1b98ce75e3.tar.gz
Adding a "fix" (cough, hack!) for method signature validation when
calling an unbound method with the instance as the first arg. By Steve Middlekauff git-svn-id: http://pymox.googlecode.com/svn/trunk@52 b1010a0a-674b-0410-b734-77272b80c875
Diffstat (limited to 'mox_test.py')
-rwxr-xr-xmox_test.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/mox_test.py b/mox_test.py
index 2e429e6..005455a 100755
--- a/mox_test.py
+++ b/mox_test.py
@@ -1496,6 +1496,59 @@ class MoxTest(unittest.TestCase):
self.assertEquals('foo', actual)
self.assertTrue(type(test_obj.OtherValidCall) is method_type)
+ def testStubOutMethod_CalledAsUnboundMethod_Comparator(self):
+ instance = TestClass()
+ self.mox.StubOutWithMock(TestClass, 'OtherValidCall')
+
+ TestClass.OtherValidCall(mox.IgnoreArg()).AndReturn('foo')
+ self.mox.ReplayAll()
+
+ actual = TestClass.OtherValidCall(instance)
+
+ self.mox.VerifyAll()
+ self.mox.UnsetStubs()
+ self.assertEquals('foo', actual)
+
+ def testStubOutMethod_CalledAsUnboundMethod_ActualInstance(self):
+ instance = TestClass()
+ self.mox.StubOutWithMock(TestClass, 'OtherValidCall')
+
+ TestClass.OtherValidCall(instance).AndReturn('foo')
+ self.mox.ReplayAll()
+
+ actual = TestClass.OtherValidCall(instance)
+
+ self.mox.VerifyAll()
+ self.mox.UnsetStubs()
+ self.assertEquals('foo', actual)
+
+ def testStubOutMethod_CalledAsUnboundMethod_DifferentInstance(self):
+ instance = TestClass()
+ self.mox.StubOutWithMock(TestClass, 'OtherValidCall')
+
+ TestClass.OtherValidCall(instance).AndReturn('foo')
+ self.mox.ReplayAll()
+
+ # This should fail, since the instances are different
+ self.assertRaises(mox.UnexpectedMethodCallError,
+ TestClass.OtherValidCall, "wrong self")
+
+
+ self.mox.VerifyAll()
+ self.mox.UnsetStubs()
+
+ def testStubOutMethod_CalledAsBoundMethod(self):
+ t = self.mox.CreateMock(TestClass)
+
+ t.MethodWithArgs(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn('foo')
+ self.mox.ReplayAll()
+
+ actual = t.MethodWithArgs(None, None);
+
+ self.mox.VerifyAll()
+ self.mox.UnsetStubs()
+ self.assertEquals('foo', actual)
+
def testStubOutClass_OldStyle(self):
"""Test a mocked class whose __init__ returns a Mock."""
self.mox.StubOutWithMock(mox_test_helper, 'TestClassFromAnotherModule')