Adds assertIn and assertNotIn support to TestCase for compatibility with python 2.6

This is a very minimal addition which doesn't require unittest2.
This commit is contained in:
Chris Behrens 2011-08-29 09:06:13 +00:00 committed by Tarmac
commit 49af6fa8e0

View File

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