Skip to content

Commit

Permalink
Removed all undue usage of lambda with assertRaises on unit tests.
Browse files Browse the repository at this point in the history
Reviewed by Lauro Neto <[email protected]>
  • Loading branch information
Marcelo Lira committed Dec 2, 2009
1 parent 9fdba43 commit 3c43320
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tests/samplebinding/argumentmodifications_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion tests/samplebinding/derived_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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++.'''
Expand Down
4 changes: 2 additions & 2 deletions tests/samplebinding/enum_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.'''
Expand Down
4 changes: 2 additions & 2 deletions tests/samplebinding/modifications_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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__':
Expand Down
8 changes: 4 additions & 4 deletions tests/samplebinding/modifiedvirtualmethods_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.'''
Expand Down Expand Up @@ -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.'''
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/samplebinding/ownership_argument_invalidation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/samplebinding/ownership_invalidate_after_use_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/samplebinding/point_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.'''
Expand Down

0 comments on commit 3c43320

Please sign in to comment.