Scott Moser has proposed merging 
~smoser/cloud-init:fix/centos-test-cloudinit-tests into cloud-init:master.

Commit message:
tests: run nosetests in cloudinit/ directory, fix py26 fallout.

When we moved some tests to live under cloudinit/ we inadvertantly
failed to change all things that would run nose to include that
directory.

This changes all the 'nose' invocations to consistently run with
tests/unittests and cloudinit/.

Also, it works around, more correctly this time, a python2.6-ism with
the following code:
   with assertRaises(SystemExit) as cm:
      sys.exit(2)

Requested reviews:
  cloud-init commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/337471

see commit message
-- 
Your team cloud-init commiters is requested to review the proposed merge of 
~smoser/cloud-init:fix/centos-test-cloudinit-tests into cloud-init:master.
diff --git a/cloudinit/cmd/tests/test_clean.py b/cloudinit/cmd/tests/test_clean.py
index 6713af4..5a3ec3b 100644
--- a/cloudinit/cmd/tests/test_clean.py
+++ b/cloudinit/cmd/tests/test_clean.py
@@ -165,10 +165,11 @@ class TestClean(CiTestCase):
             wrap_and_call(
                 'cloudinit.cmd.clean',
                 {'Init': {'side_effect': self.init_class},
+                 'sys.exit': {'side_effect': self.sys_exit},
                  'sys.argv': {'new': ['clean', '--logs']}},
                 clean.main)
 
-        self.assertRaisesCodeEqual(0, context_manager.exception.code)
+        self.assertEqual(0, context_manager.exception.code)
         self.assertFalse(
             os.path.exists(self.log1), 'Unexpected log {0}'.format(self.log1))
 
diff --git a/cloudinit/cmd/tests/test_status.py b/cloudinit/cmd/tests/test_status.py
index 4a5a8c0..37a8993 100644
--- a/cloudinit/cmd/tests/test_status.py
+++ b/cloudinit/cmd/tests/test_status.py
@@ -380,10 +380,11 @@ class TestStatus(CiTestCase):
                 wrap_and_call(
                     'cloudinit.cmd.status',
                     {'sys.argv': {'new': ['status']},
+                     'sys.exit': {'side_effect': self.sys_exit},
                      '_is_cloudinit_disabled': (False, ''),
                      'Init': {'side_effect': self.init_class}},
                     status.main)
-        self.assertRaisesCodeEqual(0, context_manager.exception.code)
+        self.assertEqual(0, context_manager.exception.code)
         self.assertEqual('status: running\n', m_stdout.getvalue())
 
 # vi: ts=4 expandtab syntax=python
diff --git a/cloudinit/tests/helpers.py b/cloudinit/tests/helpers.py
index 0080c72..41d9a8e 100644
--- a/cloudinit/tests/helpers.py
+++ b/cloudinit/tests/helpers.py
@@ -173,17 +173,15 @@ class CiTestCase(TestCase):
             dir = self.tmp_dir()
         return os.path.normpath(os.path.abspath(os.path.join(dir, path)))
 
-    def assertRaisesCodeEqual(self, expected, found):
-        """Handle centos6 having different context manager for assertRaises.
-            with assertRaises(Exception) as e:
-                raise Exception("BOO")
-
-            centos6 will have e.exception as an integer.
-            anything nwere will have it as something with a '.code'"""
-        if isinstance(found, int):
-            self.assertEqual(expected, found)
-        else:
-            self.assertEqual(expected, found.code)
+    def sys_exit(self, code):
+        """Provide a wrapper around sys.exit for python 2.6
+
+        In 2.6, this code would produce 'cm.exception' with value int(2)
+        rather than the SystemExit that was raised by sys.exit(2).
+            with assertRaises(SystemExit) as cm:
+                sys.exit(2)
+        """
+        raise SystemExit(code)
 
 
 class ResourceUsingTestCase(CiTestCase):
diff --git a/tools/run-centos b/tools/run-centos
index d58ef3e..67b2250 100755
--- a/tools/run-centos
+++ b/tools/run-centos
@@ -249,7 +249,8 @@ main() {
 
     if [ -n "$unittest" ]; then
         debug 1 "running unit tests."
-        inside_as_cd "$name" "$user" "$cdir" nosetests tests/unittests ||
+        inside_as_cd "$name" "$user" "$cdir" \
+            nosetests tests/unittests cloudinit ||
             { errorrc "nosetests failed."; errors=$(($errors+1)); }
     fi
 
diff --git a/tox.ini b/tox.ini
index bb74853..1f990af 100644
--- a/tox.ini
+++ b/tox.ini
@@ -45,7 +45,7 @@ deps = -r{toxinidir}/test-requirements.txt
 
 [testenv:py26]
 deps = -r{toxinidir}/test-requirements.txt
-commands = nosetests {posargs:tests/unittests}
+commands = nosetests {posargs:tests/unittests cloudinit}
 setenv =
     LC_ALL = C
 
@@ -83,7 +83,7 @@ deps =
 
 [testenv:centos6]
 basepython = python2.6
-commands = nosetests {posargs:tests/unittests}
+commands = nosetests {posargs:tests/unittests cloudinit}
 deps =
     # requirements
     argparse==1.2.1
@@ -98,7 +98,7 @@ deps =
 
 [testenv:opensusel42]
 basepython = python2.7
-commands = nosetests {posargs:tests/unittests}
+commands = nosetests {posargs:tests/unittests cloudinit}
 deps =
     # requirements
     argparse==1.3.0
_______________________________________________
Mailing list: https://launchpad.net/~cloud-init-dev
Post to     : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to