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
=== modified file 'autopilot/__init__.py'
--- autopilot/__init__.py 2014-01-14 20:09:40 +0000
+++ autopilot/__init__.py 2014-02-19 17:55:18 +0000
@@ -143,6 +143,10 @@
143 # http://bugs.python.org/issue16308143 # http://bugs.python.org/issue16308
144 if args.mode is None:144 if args.mode is None:
145 parser.error("too few arguments")145 parser.error("too few arguments")
146
147 if 'suite' in args:
148 args.suite = [suite.rstrip('/') for suite in args.suite]
149
146 return args150 return args
147151
148152
149153
=== modified file 'autopilot/tests/unit/test_command_line_args.py'
--- autopilot/tests/unit/test_command_line_args.py 2014-01-14 20:09:40 +0000
+++ autopilot/tests/unit/test_command_line_args.py 2014-02-19 17:55:18 +0000
@@ -33,11 +33,14 @@
3333
34from testtools import TestCase34from testtools import TestCase
35from testtools.matchers import Equals35from testtools.matchers import Equals
36from unittest import expectedFailure
3736
38from autopilot import parse_arguments37from autopilot import parse_arguments
3938
4039
40class InvalidArguments(Exception):
41 pass
42
43
41class CommandLineArgsTests(TestCase):44class CommandLineArgsTests(TestCase):
4245
43 def parse_args(self, args):46 def parse_args(self, args):
@@ -46,7 +49,7 @@
46 try:49 try:
47 return parse_arguments(args)50 return parse_arguments(args)
48 except SystemExit as e:51 except SystemExit as e:
49 self.fail("Caught exception: %r" % e)52 raise InvalidArguments("%s" % e)
5053
51 def test_launch_command_accepts_application(self):54 def test_launch_command_accepts_application(self):
52 args = self.parse_args("launch app")55 args = self.parse_args("launch app")
@@ -65,9 +68,9 @@
65 self.assertThat(args.interface, Equals("Gtk"))68 self.assertThat(args.interface, Equals("Gtk"))
6669
67 @patch('sys.stderr', new=StringIO())70 @patch('sys.stderr', new=StringIO())
68 @expectedFailure
69 def test_launch_command_fails_on_unknown_interface(self):71 def test_launch_command_fails_on_unknown_interface(self):
70 self.parse_args("launch -i unknown app")72 self.assertRaises(
73 InvalidArguments, self.parse_args, "launch -i unknown app")
7174
72 def test_launch_command_has_correct_default_verbosity(self):75 def test_launch_command_has_correct_default_verbosity(self):
73 args = self.parse_args("launch app")76 args = self.parse_args("launch app")
@@ -98,9 +101,8 @@
98 Equals(["app", "-s", "--long", "--key=val", "arg1", "arg2"]))101 Equals(["app", "-s", "--long", "--key=val", "arg1", "arg2"]))
99102
100 @patch('sys.stderr', new=StringIO())103 @patch('sys.stderr', new=StringIO())
101 @expectedFailure
102 def test_launch_command_must_specify_app(self):104 def test_launch_command_must_specify_app(self):
103 self.parse_args("launch")105 self.assertRaises(InvalidArguments, self.parse_args, "launch")
104106
105 @patch('autopilot.have_vis', new=lambda: True)107 @patch('autopilot.have_vis', new=lambda: True)
106 def test_vis_present_when_vis_module_installed(self):108 def test_vis_present_when_vis_module_installed(self):
@@ -109,9 +111,8 @@
109111
110 @patch('autopilot.have_vis', new=lambda: False)112 @patch('autopilot.have_vis', new=lambda: False)
111 @patch('sys.stderr', new=StringIO())113 @patch('sys.stderr', new=StringIO())
112 @expectedFailure
113 def test_vis_not_present_when_vis_module_not_installed(self):114 def test_vis_not_present_when_vis_module_not_installed(self):
114 self.parse_args('vis')115 self.assertRaises(InvalidArguments, self.parse_args, 'vis')
115116
116 @patch('autopilot.have_vis', new=lambda: True)117 @patch('autopilot.have_vis', new=lambda: True)
117 def test_vis_default_verbosity(self):118 def test_vis_default_verbosity(self):
@@ -219,14 +220,14 @@
219 self.assertThat(args.failfast, Equals(True))220 self.assertThat(args.failfast, Equals(True))
220221
221 @patch('sys.stderr', new=StringIO())222 @patch('sys.stderr', new=StringIO())
222 @expectedFailure
223 def test_run_command_unknown_format_short_version(self):223 def test_run_command_unknown_format_short_version(self):
224 self.parse_args('run -f unknown foo')224 self.assertRaises(
225 InvalidArguments, self.parse_args, 'run -f unknown foo')
225226
226 @patch('sys.stderr', new=StringIO())227 @patch('sys.stderr', new=StringIO())
227 @expectedFailure
228 def test_run_command_unknown_format_long_version(self):228 def test_run_command_unknown_format_long_version(self):
229 self.parse_args('run --format unknown foo')229 self.assertRaises(
230 InvalidArguments, self.parse_args, 'run --format unknown foo')
230231
231 def test_run_command_record_flag_default(self):232 def test_run_command_record_flag_default(self):
232 args = self.parse_args("run foo")233 args = self.parse_args("run foo")
@@ -306,9 +307,12 @@
306 self.assertThat(args.debug_profile, Equals('verbose'))307 self.assertThat(args.debug_profile, Equals('verbose'))
307308
308 @patch('sys.stderr', new=StringIO())309 @patch('sys.stderr', new=StringIO())
309 @expectedFailure
310 def test_cannot_select_other_debug_profile(self):310 def test_cannot_select_other_debug_profile(self):
311 self.parse_args('run --debug-profile nonexistant foo')311 self.assertRaises(
312 InvalidArguments,
313 self.parse_args,
314 'run --debug-profile nonexistant foo'
315 )
312316
313 def test_default_timeout_profile_is_normal(self):317 def test_default_timeout_profile_is_normal(self):
314 args = self.parse_args('run foo')318 args = self.parse_args('run foo')
@@ -319,6 +323,25 @@
319 self.assertThat(args.timeout_profile, Equals('long'))323 self.assertThat(args.timeout_profile, Equals('long'))
320324
321 @patch('sys.stderr', new=StringIO())325 @patch('sys.stderr', new=StringIO())
322 @expectedFailure
323 def test_cannot_select_other_timeout_profile(self):326 def test_cannot_select_other_timeout_profile(self):
324 self.parse_args('run --timeout-profile nonexistant foo')327 self.assertRaises(
328 InvalidArguments,
329 self.parse_args,
330 'run --timeout-profile nonexistant foo'
331 )
332
333 def test_list_mode_strips_single_suite_slash(self):
334 args = self.parse_args('list foo/')
335 self.assertThat(args.suite, Equals(["foo"]))
336
337 def test_list_mode_strips_multiple_suite_slash(self):
338 args = self.parse_args('list foo/ bar/')
339 self.assertThat(args.suite, Equals(["foo", "bar"]))
340
341 def test_run_mode_strips_single_suite_slash(self):
342 args = self.parse_args('run foo/')
343 self.assertThat(args.suite, Equals(["foo"]))
344
345 def test_run_mode_strips_multiple_suite_slash(self):
346 args = self.parse_args('run foo/ bar/')
347 self.assertThat(args.suite, Equals(["foo", "bar"]))

Subscribers

People subscribed via source and target branches