Merge lp:~sinzui/juju-ci-tools/notraised-init into lp:juju-ci-tools

Proposed by Curtis Hovey
Status: Merged
Merged at revision: 1976
Proposed branch: lp:~sinzui/juju-ci-tools/notraised-init
Merge into: lp:juju-ci-tools
Diff against target: 105 lines (+33/-10)
2 files modified
assess_add_cloud.py (+2/-2)
tests/test_assess_add_cloud.py (+31/-8)
To merge this branch: bzr merge lp:~sinzui/juju-ci-tools/notraised-init
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Approve
Review via email: mp+321907@code.launchpad.net

Description of the change

Pass and accept cloud_spec to NotRaised.

This fixes the error seen in CI
   assess_all_clouds TypeError: __init__() takes exactly 1 argument (2 given)
   https://bugs.launchpad.net/juju-ci-tools/+bug/1679695

NotRaised.__init__ did not accept and argument, but thought it has a cloud_spec to look the for expected exception. The caller was passing the exception, not a cloud_spec.

There are also some indentation fixes to hush lint.

To post a comment you must log in.
Revision history for this message
Aaron Bentley (abentley) wrote :

Thanks.

Your linter seems very different from flake8's.

At 51 and 60, maybe it would be better to put a newline before "spec", and indent all of the parameters to make_long_endpoint? It seems a bit odd to have parameters indented the same as the method.

review: Approve
1979. By Curtis Hovey

Revised intentation for lint.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'assess_add_cloud.py'
2--- assess_add_cloud.py 2017-02-07 22:05:20 +0000
3+++ assess_add_cloud.py 2017-04-04 19:35:45 +0000
4@@ -42,7 +42,7 @@
5 class NotRaised(Exception):
6 """An expected exception was not raised."""
7
8- def __init__(self):
9+ def __init__(self, cloud_spec):
10 msg = 'Expected exception not raised: {}'.format(
11 cloud_spec.exception)
12 super(NotRaised, self).__init__(msg)
13@@ -179,7 +179,7 @@
14 except cloud_spec.exception:
15 pass
16 else:
17- raise NotRaised(cloud_spec.exception)
18+ raise NotRaised(cloud_spec)
19 except Exception as e:
20 logging.exception(e)
21 failed.add(cloud_spec.label)
22
23=== modified file 'tests/test_assess_add_cloud.py'
24--- tests/test_assess_add_cloud.py 2017-02-07 22:05:20 +0000
25+++ tests/test_assess_add_cloud.py 2017-04-04 19:35:45 +0000
26@@ -35,8 +35,8 @@
27
28 def test_cloud_spec(self):
29 self.assertEqual(
30- CloudSpec('label1', 'name1', {'config': '1'}, None, None),
31- cloud_spec('label1', 'name1', {'config': '1'}))
32+ CloudSpec('label1', 'name1', {'config': '1'}, None, None),
33+ cloud_spec('label1', 'name1', {'config': '1'}))
34
35
36 class TestXFail(TestCase):
37@@ -63,7 +63,8 @@
38 yield client
39
40 def test_assess_cloud(self):
41- expected_cloud = {'clouds': {'foo': {
42+ expected_cloud = {'clouds': {
43+ 'foo': {
44 'type': 'maas',
45 'endpoint': 'http://bar.example.com',
46 }}}
47@@ -127,8 +128,10 @@
48 xfail(xfail(cloud_spec('invalid-name-foo', 'invalid/name', cloud,
49 exception=NameNotAccepted), 1641981, None),
50 1649721, InvalidEndpoint),
51- make_long_endpoint(spec, endpoint_validation=True)],
52- iter_clouds({'foo': cloud}, endpoint_validation=True))
53+ make_long_endpoint(
54+ spec, endpoint_validation=True)
55+ ],
56+ iter_clouds({'foo': cloud}, endpoint_validation=True))
57
58 def test_manual_no_validation(self):
59 self.maxDiff = None
60@@ -140,8 +143,10 @@
61 1641970, NameMismatch),
62 xfail(cloud_spec('invalid-name-foo', 'invalid/name', cloud,
63 exception=NameNotAccepted), 1641981, None),
64- make_long_endpoint(spec, endpoint_validation=False)],
65- iter_clouds({'foo': cloud}, endpoint_validation=False))
66+ make_long_endpoint(
67+ spec, endpoint_validation=False)
68+ ],
69+ iter_clouds({'foo': cloud}, endpoint_validation=False))
70
71 def test_vsphere(self):
72 cloud = {
73@@ -156,7 +161,8 @@
74 exception=NameNotAccepted), 1641981, None),
75 xfail(cloud_spec('long-name-foo', 'A' * 4096, cloud,
76 exception=None), 1641970, NameMismatch),
77- make_long_endpoint(spec, regions=True, endpoint_validation=True),
78+ make_long_endpoint(
79+ spec, regions=True, endpoint_validation=True),
80 ], iter_clouds({'foo': cloud}, endpoint_validation=True))
81
82 def test_vsphere_no_validation(self):
83@@ -287,6 +293,23 @@
84 self.assertEqual({27: {'label1'}}, xfailed)
85 self.assertEqual(0, exception_mock.call_count)
86
87+ def test_failed_notraised(self):
88+ client = fake_juju_client(juju_home=self.juju_home)
89+ cloud_specs = [
90+ cloud_spec('label', 'name', {'config': '1'}, TypeNotAccepted)]
91+ with patch('assess_add_cloud.assess_cloud'):
92+ with patch('logging.exception') as exception_mock:
93+ with patch('sys.stdout'):
94+ succeeded, xfailed, failed = assess_all_clouds(client,
95+ cloud_specs)
96+ self.assertEqual(set(['label']), failed)
97+ self.assertEqual(1, exception_mock.call_count)
98+ raised_e = exception_mock.mock_calls[0][1][0]
99+ self.assertEqual(
100+ "Expected exception not raised: "
101+ "<class 'jujupy.client.TypeNotAccepted'>",
102+ raised_e.message)
103+
104
105 class TestWriteStatus(FakeHomeTestCase):
106

Subscribers

People subscribed via source and target branches