From 587bac87604aadd4d7aedba2a911bfcac9671fe3 Mon Sep 17 00:00:00 2001 From: Marcelo Lira Date: Wed, 11 May 2011 18:15:40 -0300 Subject: Replaced "isUserType" test for the correct "hasCppWrapper" before method calls. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also added an unit test for infinite recursion when duck punching a virtual method. Reviewed by Hugo Parente Reviewed by Renato Araújo --- tests/samplebinding/duck_punching_test.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests') diff --git a/tests/samplebinding/duck_punching_test.py b/tests/samplebinding/duck_punching_test.py index 013e36468..2870b8c47 100644 --- a/tests/samplebinding/duck_punching_test.py +++ b/tests/samplebinding/duck_punching_test.py @@ -45,6 +45,7 @@ class DuckPunchingTest(unittest.TestCase): def setUp(self): self.multiplier = 2.0 self.duck_method_called = False + self.call_counter = 0 def testMonkeyPatchOnVirtualMethod(self): '''Injects new 'virtualMethod0' on a VirtualMethods instance and makes C++ call it.''' @@ -147,6 +148,17 @@ class DuckPunchingTest(unittest.TestCase): monkey.exists = None + def testForInfiniteRecursion(self): + def myVirtualMethod0(obj, pt, val, cpx, b): + self.call_counter += 1 + return VirtualMethods.virtualMethod0(obj, pt, val, cpx, b) + vm = VirtualMethods() + vm.virtualMethod0 = types.MethodType(myVirtualMethod0, vm, VirtualMethods) + pt, val, cpx, b = Point(1.1, 2.2), 4, complex(3.3, 4.4), True + vm.virtualMethod0(pt, val, cpx, b) + self.assertEqual(self.call_counter, 1) + + if __name__ == '__main__': unittest.main() -- cgit v1.2.3