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:
commit
49af6fa8e0
18
nova/test.py
18
nova/test.py
@ -277,3 +277,21 @@ class TestCase(unittest.TestCase):
|
|||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
self.assertEqual(sub_value, super_value)
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user