fix for assertIn and assertNotIn use which was added in python 2.7. this makes things work on 2.6 still

This commit is contained in:
Chris Behrens
2011-08-28 23:39:43 -07:00
parent d7f7511898
commit e9cf2041ab

View File

@@ -277,3 +277,21 @@ class TestCase(unittest.TestCase):
continue
else:
self.assertEqual(sub_value, super_value)
def assertIn(self, a, b):
"""Python < v2.7 compatibility. Assert 'a' in 'b'"""
try:
f = super(TestCase, self).assertIn
except AttributeError:
self.assertTrue(a in b)
else:
f(a, b)
def assertNotIn(self, a, b):
"""Python < v2.7 compatibility. Assert 'a' NOT in 'b'"""
try:
f = super(TestCase, self).assertNotIn
except AttributeError:
self.assertFalse(a in b)
else:
f(a, b)