Merge lp:~coreygoldberg/autopilot/fix-tests-1281733 into lp:autopilot

Proposed by Corey Goldberg
Status: Merged
Approved by: Thomi Richards
Approved revision: 440
Merged at revision: 441
Proposed branch: lp:~coreygoldberg/autopilot/fix-tests-1281733
Merge into: lp:autopilot
Diff against target: 139 lines (+43/-16)
2 files modified
autopilot/__init__.py (+4/-0)
autopilot/tests/unit/test_command_line_args.py (+39/-16)
To merge this branch: bzr merge lp:~coreygoldberg/autopilot/fix-tests-1281733
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Thomi Richards (community) Approve
Review via email: mp+207071@code.launchpad.net

Commit message

Fix test_command_line_args issues with python 3.4.

Description of the change

@expectedFailure decorator is breaking in python3.4,

this branch removes it's use in test_command_line_args.py and refactors the tests to do an assertRaises.

all unit tests now pass in python3.4.

To post a comment you must log in.
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

A few comments:

1) you don't need to import ExpectedException any more.

2) Please rename your exception to 'InvalidArguments' - there's no need to have both ''Invalid' and 'Error' in the exception name.

3) When raising The InvalidArguments Error, just do:

raise InvalidArguments("%s" % e)

(note the '%s' instead of '%r').

Otherwise, LGTM - make sure you run flake8 over it as well.

review: Needs Fixing
439. By Corey Goldberg

unused imports removed

440. By Corey Goldberg

fixed flake8 and review comments

Revision history for this message
Corey Goldberg (coreygoldberg) wrote :

fixed per thomi's comments

Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Looks fantastic to me!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
441. By Corey Goldberg

fixed merge conflict

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'autopilot/__init__.py'
2--- autopilot/__init__.py 2014-01-14 20:09:40 +0000
3+++ autopilot/__init__.py 2014-02-19 17:55:18 +0000
4@@ -143,6 +143,10 @@
5 # http://bugs.python.org/issue16308
6 if args.mode is None:
7 parser.error("too few arguments")
8+
9+ if 'suite' in args:
10+ args.suite = [suite.rstrip('/') for suite in args.suite]
11+
12 return args
13
14
15
16=== modified file 'autopilot/tests/unit/test_command_line_args.py'
17--- autopilot/tests/unit/test_command_line_args.py 2014-01-14 20:09:40 +0000
18+++ autopilot/tests/unit/test_command_line_args.py 2014-02-19 17:55:18 +0000
19@@ -33,11 +33,14 @@
20
21 from testtools import TestCase
22 from testtools.matchers import Equals
23-from unittest import expectedFailure
24
25 from autopilot import parse_arguments
26
27
28+class InvalidArguments(Exception):
29+ pass
30+
31+
32 class CommandLineArgsTests(TestCase):
33
34 def parse_args(self, args):
35@@ -46,7 +49,7 @@
36 try:
37 return parse_arguments(args)
38 except SystemExit as e:
39- self.fail("Caught exception: %r" % e)
40+ raise InvalidArguments("%s" % e)
41
42 def test_launch_command_accepts_application(self):
43 args = self.parse_args("launch app")
44@@ -65,9 +68,9 @@
45 self.assertThat(args.interface, Equals("Gtk"))
46
47 @patch('sys.stderr', new=StringIO())
48- @expectedFailure
49 def test_launch_command_fails_on_unknown_interface(self):
50- self.parse_args("launch -i unknown app")
51+ self.assertRaises(
52+ InvalidArguments, self.parse_args, "launch -i unknown app")
53
54 def test_launch_command_has_correct_default_verbosity(self):
55 args = self.parse_args("launch app")
56@@ -98,9 +101,8 @@
57 Equals(["app", "-s", "--long", "--key=val", "arg1", "arg2"]))
58
59 @patch('sys.stderr', new=StringIO())
60- @expectedFailure
61 def test_launch_command_must_specify_app(self):
62- self.parse_args("launch")
63+ self.assertRaises(InvalidArguments, self.parse_args, "launch")
64
65 @patch('autopilot.have_vis', new=lambda: True)
66 def test_vis_present_when_vis_module_installed(self):
67@@ -109,9 +111,8 @@
68
69 @patch('autopilot.have_vis', new=lambda: False)
70 @patch('sys.stderr', new=StringIO())
71- @expectedFailure
72 def test_vis_not_present_when_vis_module_not_installed(self):
73- self.parse_args('vis')
74+ self.assertRaises(InvalidArguments, self.parse_args, 'vis')
75
76 @patch('autopilot.have_vis', new=lambda: True)
77 def test_vis_default_verbosity(self):
78@@ -219,14 +220,14 @@
79 self.assertThat(args.failfast, Equals(True))
80
81 @patch('sys.stderr', new=StringIO())
82- @expectedFailure
83 def test_run_command_unknown_format_short_version(self):
84- self.parse_args('run -f unknown foo')
85+ self.assertRaises(
86+ InvalidArguments, self.parse_args, 'run -f unknown foo')
87
88 @patch('sys.stderr', new=StringIO())
89- @expectedFailure
90 def test_run_command_unknown_format_long_version(self):
91- self.parse_args('run --format unknown foo')
92+ self.assertRaises(
93+ InvalidArguments, self.parse_args, 'run --format unknown foo')
94
95 def test_run_command_record_flag_default(self):
96 args = self.parse_args("run foo")
97@@ -306,9 +307,12 @@
98 self.assertThat(args.debug_profile, Equals('verbose'))
99
100 @patch('sys.stderr', new=StringIO())
101- @expectedFailure
102 def test_cannot_select_other_debug_profile(self):
103- self.parse_args('run --debug-profile nonexistant foo')
104+ self.assertRaises(
105+ InvalidArguments,
106+ self.parse_args,
107+ 'run --debug-profile nonexistant foo'
108+ )
109
110 def test_default_timeout_profile_is_normal(self):
111 args = self.parse_args('run foo')
112@@ -319,6 +323,25 @@
113 self.assertThat(args.timeout_profile, Equals('long'))
114
115 @patch('sys.stderr', new=StringIO())
116- @expectedFailure
117 def test_cannot_select_other_timeout_profile(self):
118- self.parse_args('run --timeout-profile nonexistant foo')
119+ self.assertRaises(
120+ InvalidArguments,
121+ self.parse_args,
122+ 'run --timeout-profile nonexistant foo'
123+ )
124+
125+ def test_list_mode_strips_single_suite_slash(self):
126+ args = self.parse_args('list foo/')
127+ self.assertThat(args.suite, Equals(["foo"]))
128+
129+ def test_list_mode_strips_multiple_suite_slash(self):
130+ args = self.parse_args('list foo/ bar/')
131+ self.assertThat(args.suite, Equals(["foo", "bar"]))
132+
133+ def test_run_mode_strips_single_suite_slash(self):
134+ args = self.parse_args('run foo/')
135+ self.assertThat(args.suite, Equals(["foo"]))
136+
137+ def test_run_mode_strips_multiple_suite_slash(self):
138+ args = self.parse_args('run foo/ bar/')
139+ self.assertThat(args.suite, Equals(["foo", "bar"]))

Subscribers

People subscribed via source and target branches