cloud-init-dev team mailing list archive
-
cloud-init-dev team
-
Mailing list archive
-
Message #00162
[Merge] lp:~harlowja/cloud-init/testcase-assert-fixes into lp:cloud-init
Joshua Harlow has proposed merging lp:~harlowja/cloud-init/testcase-assert-fixes into lp:cloud-init.
Requested reviews:
cloud init development team (cloud-init-dev)
Related bugs:
Bug #1078473 in cloud-init: "Python 2.6 assertIn/NotIn"
https://bugs.launchpad.net/cloud-init/+bug/1078473
For more details, see:
https://code.launchpad.net/~harlowja/cloud-init/testcase-assert-fixes/+merge/134232
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
--
https://code.launchpad.net/~harlowja/cloud-init/testcase-assert-fixes/+merge/134232
Your team cloud init development team is requested to review the proposed merge of lp:~harlowja/cloud-init/testcase-assert-fixes into lp:cloud-init.
=== modified file 'tests/unittests/helpers.py'
--- tests/unittests/helpers.py 2012-11-10 18:15:16 +0000
+++ tests/unittests/helpers.py 2012-11-13 23:52:21 +0000
@@ -1,4 +1,6 @@
import os
+import sys
+import unittest
from mocker import MockerTestCase
@@ -7,6 +9,27 @@
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
=== modified file 'tests/unittests/test_handler/test_handler_power_state.py'
--- tests/unittests/test_handler/test_handler_power_state.py 2012-11-13 16:18:22 +0000
+++ tests/unittests/test_handler/test_handler_power_state.py 2012-11-13 23:52:21 +0000
@@ -1,9 +1,9 @@
-from unittest import TestCase
-
from cloudinit.config import cc_power_state_change as psc
-
-class TestLoadPowerState(TestCase):
+from tests.unittests import helpers as t_help
+
+
+class TestLoadPowerState(t_help.TestCase):
def setUp(self):
super(self.__class__, self).setUp()