diff options
author | Chris Behrens <cbehrens@codestud.com> | 2011-08-29 09:06:13 +0000 |
---|---|---|
committer | Tarmac <> | 2011-08-29 09:06:13 +0000 |
commit | 49af6fa8e07b566237e6b80244ffe117568957d5 (patch) | |
tree | d7b2b6ad2202e36ae1154e48d22f16698568a9d4 | |
parent | 0ef2581749f39fa4fd41c2376186418e730f0afb (diff) | |
parent | 8bfa5e23e90279dfdbef3e38fca810ccca540513 (diff) | |
download | nova-49af6fa8e07b566237e6b80244ffe117568957d5.tar.gz nova-49af6fa8e07b566237e6b80244ffe117568957d5.tar.xz nova-49af6fa8e07b566237e6b80244ffe117568957d5.zip |
Adds assertIn and assertNotIn support to TestCase for compatibility with python 2.6
This is a very minimal addition which doesn't require unittest2.
-rw-r--r-- | nova/test.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/nova/test.py b/nova/test.py index 88f1489e8..d759aef60 100644 --- a/nova/test.py +++ b/nova/test.py @@ -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) |