From 599467124e812eb8ae73eb7a9af3fea71ee25157 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Sun, 28 Aug 2011 23:39:43 -0700 Subject: [PATCH 1/2] fix for assertIn and assertNotIn use which was added in python 2.7. this makes things work on 2.6 still --- nova/test.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/nova/test.py b/nova/test.py index 88f1489e81f1..d1c1ad20e704 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): + """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) From 8bfa5e23e90279dfdbef3e38fca810ccca540513 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Mon, 29 Aug 2011 01:13:08 -0700 Subject: [PATCH 2/2] support the extra optional arguments for msg to assertIn and assertNotIn --- nova/test.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/nova/test.py b/nova/test.py index d1c1ad20e704..d759aef6076e 100644 --- a/nova/test.py +++ b/nova/test.py @@ -278,20 +278,20 @@ class TestCase(unittest.TestCase): else: self.assertEqual(sub_value, super_value) - def assertIn(self, a, b): + 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) + self.assertTrue(a in b, *args, **kwargs) else: - f(a, b) + f(a, b, *args, **kwargs) - def assertNotIn(self, a, b): + 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) + self.assertFalse(a in b, *args, **kwargs) else: - f(a, b) + f(a, b, *args, **kwargs)