summaryrefslogtreecommitdiff
path: root/tests/unittests/helpers.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2015-01-26 20:02:31 -0500
committerBarry Warsaw <barry@python.org>2015-01-26 20:02:31 -0500
commit5e2b8ef0703eb4582a5a8ba50ae7c83a8294d65a (patch)
tree9f3c2d6d7cdd3e63e52d54152d3dbb15e916d9f3 /tests/unittests/helpers.py
parentfe99f7d6d87e88320933957b2933288c6eb2986d (diff)
downloadvyos-cloud-init-5e2b8ef0703eb4582a5a8ba50ae7c83a8294d65a.tar.gz
vyos-cloud-init-5e2b8ef0703eb4582a5a8ba50ae7c83a8294d65a.zip
Repair the Python 2.6 tests.
Diffstat (limited to 'tests/unittests/helpers.py')
-rw-r--r--tests/unittests/helpers.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/tests/unittests/helpers.py b/tests/unittests/helpers.py
index 828579e8..424d0626 100644
--- a/tests/unittests/helpers.py
+++ b/tests/unittests/helpers.py
@@ -39,8 +39,20 @@ else:
PY3 = True
if PY26:
- # For now add these on, taken from python 2.7 + slightly adjusted
+ # For now add these on, taken from python 2.7 + slightly adjusted. Drop
+ # all this once Python 2.6 is dropped as a minimum requirement.
class TestCase(unittest.TestCase):
+ def setUp(self):
+ unittest.TestCase.setUp(self)
+ self.__all_cleanups = ExitStack()
+
+ def tearDown(self):
+ self.__all_cleanups.close()
+ unittest.TestCase.tearDown(self)
+
+ def addCleanup(self, function, *args, **kws):
+ self.__all_cleanups.callback(function, *args, **kws)
+
def assertIs(self, expr1, expr2, msg=None):
if expr1 is not expr2:
standardMsg = '%r is not %r' % (expr1, expr2)
@@ -63,6 +75,13 @@ if PY26:
standardMsg = standardMsg % (value)
self.fail(self._formatMessage(msg, standardMsg))
+ def assertIsInstance(self, obj, cls, msg=None):
+ """Same as self.assertTrue(isinstance(obj, cls)), with a nicer
+ default message."""
+ if not isinstance(obj, cls):
+ standardMsg = '%s is not an instance of %r' % (repr(obj), cls)
+ self.fail(self._formatMessage(msg, standardMsg))
+
def assertDictContainsSubset(self, expected, actual, msg=None):
missing = []
mismatched = []
@@ -126,9 +145,9 @@ def retarget_many_wrapper(new_base, am, old_func):
return wrapper
-class ResourceUsingTestCase(unittest.TestCase):
+class ResourceUsingTestCase(TestCase):
def setUp(self):
- unittest.TestCase.setUp(self)
+ TestCase.setUp(self)
self.resource_path = None
def resourceLocation(self, subname=None):