I'm relatively new to unittesting in python and find that some tasks are quite arduous and I've seen nicer packages in other languages.
I've been wondering if there are packages that help me for example with shortening validation of complex properties (of which I tend to have a lot) like below, or if there are none, is there any reason I should not consider writing them?
def test_lengthProperty(self):
tester = new PropertyTester(instance.property)
# assert raises TypeError
tester = tester.withInstanceValidation('pass': (int, long, float))
tester = telter.withInstanceValidation('fail': (str, complex, unicode, ...))
# assert raises ValueError
tester = tester.withMinValue({'pass': (0), 'fail':(-1)})
tester = tester.withMaxValue({'pass': (100), 'fail': (101)})
# assert the values are just stored not adjusted.
tester = tester.setterEqualsGetter({'pass' : range(101)})
tester.assertAll()
def test_dateProperty(self):
# assert raises TypeError
tester = tester.withSubclassValidation('pass': (datetime.date))
tester = tester.withInstanceValidation('fail': (str, complex, unicode, ...))
# Assert adjusts invalid dates
tester = tester.assertAdjust(
{'input' : date(2010, 31, 12),
'output': date(2011, 1,1)})
tester.assertAll()
TypeError
, then useunittest.TestCase.assertRaises()
withTypeError
as the first argument. TheTestCase
class provides a whole host of methods to check for and report failures. – Johnsyweb Apr 2 '14 at 22:30