From 3c433205280de89d4d7709dfb29426492fdbdbe6 Mon Sep 17 00:00:00 2001 From: Marcelo Lira Date: Tue, 1 Dec 2009 21:26:20 -0300 Subject: [PATCH] Removed all undue usage of lambda with assertRaises on unit tests. Reviewed by Lauro Neto --- tests/samplebinding/argumentmodifications_test.py | 2 +- tests/samplebinding/derived_test.py | 2 +- tests/samplebinding/enum_test.py | 4 ++-- tests/samplebinding/modifications_test.py | 4 ++-- tests/samplebinding/modifiedvirtualmethods_test.py | 8 ++++---- .../samplebinding/ownership_argument_invalidation_test.py | 6 +++--- .../samplebinding/ownership_invalidate_after_use_test.py | 2 +- tests/samplebinding/point_test.py | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/samplebinding/argumentmodifications_test.py b/tests/samplebinding/argumentmodifications_test.py index aa75f8c..8cf5c4d 100755 --- a/tests/samplebinding/argumentmodifications_test.py +++ b/tests/samplebinding/argumentmodifications_test.py @@ -84,7 +84,7 @@ def testArgRemoval4(self): # void [-> PyObject*] argRemoval4(int, Point [removed, new val = Point(6, 9)], bool, Point = Point(3, 4) [removed], int = 333) # code-injection: returns tuple with received parameters plus removed ones a0, a1, a2 = 1, True, 2 - self.assertRaises(TypeError, lambda : self.mods.argRemoval4(a0)) + self.assertRaises(TypeError, self.mods.argRemoval4, a0) self.assertEqual(self.mods.argRemoval4(a0, a1), (a0, Point(6, 9), a1, Point(3, 4), 333)) self.assertEqual(self.mods.argRemoval4(a0, a1, a2), (a0, Point(6, 9), a1, Point(3, 4), a2)) diff --git a/tests/samplebinding/derived_test.py b/tests/samplebinding/derived_test.py index 5077bd5..32d70f4 100755 --- a/tests/samplebinding/derived_test.py +++ b/tests/samplebinding/derived_test.py @@ -94,7 +94,7 @@ def testOverloadedMethodCallWithDifferentNumericTypes(self): def testOverloadedMethodCallWithWrongNumberOfArguments(self): '''Test if a call to an overloaded method with the wrong number of arguments raises an exception.''' derived = Derived() - self.assertRaises(TypeError, lambda : derived.otherOverloaded(1, 2, True)) + self.assertRaises(TypeError, derived.otherOverloaded, 1, 2, True) def testReimplementedPureVirtualMethodCall(self): '''Test if a Python override of a implemented pure virtual method is correctly called from C++.''' diff --git a/tests/samplebinding/enum_test.py b/tests/samplebinding/enum_test.py index d146db4..e282cdc 100755 --- a/tests/samplebinding/enum_test.py +++ b/tests/samplebinding/enum_test.py @@ -36,11 +36,11 @@ class EnumTest(unittest.TestCase): def testPassingIntegerOnEnumArgument(self): '''Tries to use an integer in place of an enum argument.''' - self.assertRaises(TypeError, lambda : SampleNamespace.getNumber(1)) + self.assertRaises(TypeError, SampleNamespace.getNumber, 1) def testExtendingNonExtensibleEnum(self): '''Tries to create a new enum item for an unextensible enum.''' - self.assertRaises(TypeError, lambda : SampleNamespace.InValue(13)) + self.assertRaises(TypeError, SampleNamespace.InValue, 13) def testEnumConversionToAndFromPython(self): '''Conversion of enum objects from Python to C++ back again.''' diff --git a/tests/samplebinding/modifications_test.py b/tests/samplebinding/modifications_test.py index e0c6aa7..9a33c25 100755 --- a/tests/samplebinding/modifications_test.py +++ b/tests/samplebinding/modifications_test.py @@ -82,7 +82,7 @@ def testRegularMethodRemoval(self): def testArgumentRemoval(self): '''Test if second argument of Modifications::doublePlus(int, int) was removed.''' - self.assertRaises(TypeError, lambda : self.mods.doublePlus(3, 7)) + self.assertRaises(TypeError, self.mods.doublePlus, 3, 7) self.assertEqual(self.mods.doublePlus(7), 14) def testDefaultValueRemoval(self): @@ -131,7 +131,7 @@ def testOverloadedMethodModifications(self): # the others weren't modified self.assertEqual(self.mods.overloaded(1, True, 2, False), Modifications.Overloaded_ibib) self.assertEqual(self.mods.overloaded(1, False, 2, Point(3, 4)), Modifications.Overloaded_ibiP) - self.assertRaises(TypeError, lambda : self.mods.overloaded(1, True, Point(2, 3), Point(4, 5))) + self.assertRaises(TypeError, self.mods.overloaded, 1, True, Point(2, 3), Point(4, 5)) self.assertEqual(self.mods.over(1, True, Point(2, 3), Point(4, 5)), Modifications.Overloaded_ibPP) if __name__ == '__main__': diff --git a/tests/samplebinding/modifiedvirtualmethods_test.py b/tests/samplebinding/modifiedvirtualmethods_test.py index 128c7d1..2086776 100755 --- a/tests/samplebinding/modifiedvirtualmethods_test.py +++ b/tests/samplebinding/modifiedvirtualmethods_test.py @@ -94,7 +94,7 @@ def testModifiedVirtualMethod0(self): result1 = self.vm.sumThree(a0, a1, a2) self.assertEqual(result0, a0 + a1 + a2) self.assertEqual(result0, result1) - self.assertRaises(AttributeError, lambda : self.vm.sum0(a0, a1, a2)) + self.assertRaises(AttributeError, getattr, self.vm, 'sum0') def testReimplementedModifiedVirtualMethod0(self): '''Override of a renamed virtual method.''' @@ -132,7 +132,7 @@ def testModifiedVirtualMethod2(self): result1 = self.vm.sum2(a0, a1) result2 = self.vm.callSum2(a0, a1, 2000) self.assertEqual(result1, result2) - self.assertRaises(TypeError, lambda : self.vm.sum2(1, 2, 3)) + self.assertRaises(TypeError, self.vm.sum2, 1, 2, 3) def testReimplementedModifiedVirtualMethod2(self): '''Override of the virtual method originally with three arguments, the last one was removed and the default value set to 2000.''' @@ -153,7 +153,7 @@ def testModifiedVirtualMethod3(self): self.assertNotEqual(result0, result1) result2 = self.vm.callSum3(a0, a0 + a1, a1) self.assertEqual(result0, result2) - self.assertRaises(TypeError, lambda : self.vm.sum3(1, 2, 3)) + self.assertRaises(TypeError, self.vm.sum3, 1, 2, 3) def testReimplementedModifiedVirtualMethod3(self): '''Override of the virtual method originally with three arguments have the second one removed and replaced @@ -175,7 +175,7 @@ def testModifiedVirtualMethod4(self): removed_arg_value = 100 result1 = self.vm.callSum4(a0, removed_arg_value, a1) self.assertEqual(result1, a0 + removed_arg_value + a1) - self.assertRaises(TypeError, lambda : self.vm.sum4(1, 2, 3)) + self.assertRaises(TypeError, self.vm.sum4, 1, 2, 3) def testReimplementedModifiedVirtualMethod4(self): '''Override of the virtual method originally with three arguments, the last one was removed diff --git a/tests/samplebinding/ownership_argument_invalidation_test.py b/tests/samplebinding/ownership_argument_invalidation_test.py index 6562a28..8a6aac7 100755 --- a/tests/samplebinding/ownership_argument_invalidation_test.py +++ b/tests/samplebinding/ownership_argument_invalidation_test.py @@ -38,19 +38,19 @@ def testInvalidArgumentToMethod(self): '''Call to method using invalidated Python wrapper as argument should raise RuntimeError.''' poly = Polygon() Polygon.stealOwnershipFromPython(poly) - self.assertRaises(RuntimeError, lambda : Polygon.doublePolygonScale(poly)) + self.assertRaises(RuntimeError, Polygon.doublePolygonScale, poly) def testInvalidArgumentToConstructor(self): '''Call to constructor using invalidated Python wrapper as argument should raise RuntimeError.''' pt = Point(1, 2) Polygon.stealOwnershipFromPython(pt) - self.assertRaises(RuntimeError, lambda : Polygon(pt)) + self.assertRaises(RuntimeError, Polygon, pt) def testInvalidArgumentWithImplicitConversion(self): '''Call to method using invalidated Python wrapper to be implicitly converted should raise RuntimeError.''' pt = Point(1, 2) Polygon.stealOwnershipFromPython(pt) - self.assertRaises(RuntimeError, lambda : Polygon.doublePolygonScale(pt)) + self.assertRaises(RuntimeError, Polygon.doublePolygonScale, pt) if __name__ == '__main__': unittest.main() diff --git a/tests/samplebinding/ownership_invalidate_after_use_test.py b/tests/samplebinding/ownership_invalidate_after_use_test.py index 5f9930e..80f252d 100755 --- a/tests/samplebinding/ownership_invalidate_after_use_test.py +++ b/tests/samplebinding/ownership_invalidate_after_use_test.py @@ -59,7 +59,7 @@ def testObjectInvalidatedAfterUseAsParameter(self): ot = ObjectType() eot.causeEvent(Event.ANY_EVENT) self.assertEqual(eot.type_of_last_event, Event.ANY_EVENT) - self.assertRaises(RuntimeError, lambda : ot.event(eot.last_event)) + self.assertRaises(RuntimeError, ot.event, eot.last_event) if __name__ == '__main__': unittest.main() diff --git a/tests/samplebinding/point_test.py b/tests/samplebinding/point_test.py index 4530685..c5b1bf2 100755 --- a/tests/samplebinding/point_test.py +++ b/tests/samplebinding/point_test.py @@ -59,7 +59,7 @@ def testNotEqualOperator(self): '''Test Point class != operator.''' pt1 = Point(5.0, 2.3) pt2 = Point(5.0, 2.3) - self.assertRaises(NotImplementedError, lambda : pt1.__ne__(pt2)) + self.assertRaises(NotImplementedError, pt1.__ne__, pt2) def testReturnNewCopy(self): '''Point returns a copy of itself.'''