Ubuntu Pastebin

Paste from smoser at Thu, 7 Dec 2017 22:12:00 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
diff --git a/cloudinit/cmd/tests/test_clean.py b/cloudinit/cmd/tests/test_clean.py
index af438aa..cc19513 100644
--- a/cloudinit/cmd/tests/test_clean.py
+++ b/cloudinit/cmd/tests/test_clean.py
@@ -151,7 +151,7 @@ class TestClean(CiTestCase):
                  'sys.argv': {'new': ['clean', '--logs']}},
                 clean.main)
 
-        self.assertEqual(0, context_manager.exception.code)
+        self.assertRaisesCodeEqual(0, context_manager.exception)
         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 8ec9b5b..5463fca 100644
--- a/cloudinit/cmd/tests/test_status.py
+++ b/cloudinit/cmd/tests/test_status.py
@@ -347,7 +347,7 @@ class TestStatus(CiTestCase):
                      '_is_cloudinit_disabled': (False, ''),
                      'Init': {'side_effect': self.init_class}},
                     status.main)
-        self.assertEqual(0, context_manager.exception.code)
+        self.assertRaisesCodeEqual(0, context_manager.exception)
         self.assertEqual('status: running\n', m_stdout.getvalue())
 
 # vi: ts=4 expandtab syntax=python
diff --git a/cloudinit/helpers.py b/cloudinit/helpers.py
index 1979cd9..5be0d64 100644
--- a/cloudinit/helpers.py
+++ b/cloudinit/helpers.py
@@ -449,4 +449,5 @@ class DefaultingConfigParser(RawConfigParser):
             contents = '\n'.join([header, contents, ''])
         return contents
 
+
 # vi: ts=4 expandtab
diff --git a/cloudinit/tests/helpers.py b/cloudinit/tests/helpers.py
index feb884a..d10f536 100644
--- a/cloudinit/tests/helpers.py
+++ b/cloudinit/tests/helpers.py
@@ -158,6 +158,18 @@ 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)
+
 
 class ResourceUsingTestCase(CiTestCase):
 
@@ -395,4 +407,8 @@ if not hasattr(mock.Mock, 'assert_not_called'):
     mock.Mock.assert_not_called = __mock_assert_not_called
 
 
+# older unittest2.TestCase (centos6) do not have assertRaisesRegex
+if not hasattr(unittest2.TestCase, 'assertRaisesRegex'):
+    unittest2.TestCase.assertRaisesRegex = unittest2.TestCase.assertRaisesRegexp
+
 # vi: ts=4 expandtab
diff --git a/tox.ini b/tox.ini
index d7316cc..11aa063 100644
--- a/tox.ini
+++ b/tox.ini
@@ -21,7 +21,7 @@ setenv =
     LC_ALL = en_US.utf-8
 
 [testenv:pylint]
-basepython = python3
+basepython = python
 deps =
     # requirements
     pylint==1.7.1
Download as text