summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-11-13 15:49:46 -0800
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-11-13 15:49:46 -0800
commitdb79dbe2c7d55d1240a570ee6042e50f7d50c94d (patch)
treece1c1e0f2323578b3837a391c33dc2434aab37b7
parent290f5d6a3a8024d4371118cee9da4cde75d2a0aa (diff)
downloadcloud-init-db79dbe2c7d55d1240a570ee6042e50f7d50c94d.tar.gz
Create a utility testcase class that fixes some of the 2.6 missing pieces
- Add a helper testcase class that can add additional features into the unit test class as we need for features that are useful to have which starts with features that are missing including assertIn and assertNotIn
-rw-r--r--tests/unittests/helpers.py23
-rw-r--r--tests/unittests/test_handler/test_handler_power_state.py6
2 files changed, 26 insertions, 3 deletions
diff --git a/tests/unittests/helpers.py b/tests/unittests/helpers.py
index e8080668..92540b0c 100644
--- a/tests/unittests/helpers.py
+++ b/tests/unittests/helpers.py
@@ -1,4 +1,6 @@
import os
+import sys
+import unittest
from mocker import MockerTestCase
@@ -7,6 +9,27 @@ from cloudinit import util
import shutil
+# Handle how 2.6 doesn't have the assertIn or assertNotIn
+_PY_VER = sys.version_info
+_PY_MAJOR, _PY_MINOR = _PY_VER[0:2]
+if (_PY_MAJOR, _PY_MINOR) <= (2, 6):
+ # For now add these on, taken from python 2.7 + slightly adjusted
+ class TestCase(unittest.TestCase):
+ def assertIn(self, member, container, msg=None):
+ if member not in container:
+ standardMsg = '%r not found in %r' % (member, container)
+ self.fail(self._formatMessage(msg, standardMsg))
+
+ def assertNotIn(self, member, container, msg=None):
+ if member in container:
+ standardMsg = '%r unexpectedly found in %r'
+ standardMsg = standardMsg % (member, container)
+ self.fail(self._formatMessage(msg, standardMsg))
+
+else:
+ class TestCase(unittest.TestCase):
+ pass
+
# Makes the old path start
# with new base instead of whatever
diff --git a/tests/unittests/test_handler/test_handler_power_state.py b/tests/unittests/test_handler/test_handler_power_state.py
index 1149fedc..f6e37fa5 100644
--- a/tests/unittests/test_handler/test_handler_power_state.py
+++ b/tests/unittests/test_handler/test_handler_power_state.py
@@ -1,9 +1,9 @@
-from unittest import TestCase
-
from cloudinit.config import cc_power_state_change as psc
+from tests.unittests import helpers as t_help
+
-class TestLoadPowerState(TestCase):
+class TestLoadPowerState(t_help.TestCase):
def setUp(self):
super(self.__class__, self).setUp()