Message123745
It would be useful to have a new assert method in the unittest.TestCase class that checks to see if a value has changed. I wrote a quick and dirty version like so:
class MySpecialTestCase(unittest.TestCase):
@contextmanager
def assertChanges(self, thing, attr=None, by=None):
def get_value(thing, attr):
if callable(thing):
value = thing()
else:
value = getattr(thing, attr)
return value
old_value = get_value(thing, attr)
yield
new_value = get_value(thing, attr)
if by is None:
self.assertNotEqual(new_value, old_value)
else:
self.assertEqual(new_value - old_value, by)
I'm sure something better can be done to take better advantage of the unittest module's diffing tools, etc. |
|
Date |
User |
Action |
Args |
2010-12-10 19:58:36 | Jay.Moorthi | set | recipients:
+ Jay.Moorthi |
2010-12-10 19:58:36 | Jay.Moorthi | set | messageid: <1292011116.36.0.95630190465.issue10675@psf.upfronthosting.co.za> |
2010-12-10 19:58:34 | Jay.Moorthi | link | issue10675 messages |
2010-12-10 19:58:34 | Jay.Moorthi | create | |
|