Merge lp:~bac/testrepository/bug-949950 into lp:~testrepository/testrepository/trunk

Proposed by Brad Crittenden on 2012-04-17
Status: Rejected
Rejected by: Jonathan Lange on 2012-04-18
Proposed branch: lp:~bac/testrepository/bug-949950
Merge into: lp:~testrepository/testrepository/trunk
Diff against target: 145 lines (+35/-13)
4 files modified
testrepository/commands/run.py (+7/-8)
testrepository/tests/test_ui.py (+21/-4)
testrepository/tests/ui/test_cli.py (+1/-0)
testrepository/ui/cli.py (+6/-1)
To merge this branch: bzr merge lp:~bac/testrepository/bug-949950
Reviewer Review Type Date Requested Status
Jonathan Lange 2012-04-17 Disapprove on 2012-04-17
Review via email: mp+102317@code.launchpad.net

Description of the Change

As requested, a '--subunit' option was added to the run command to get results in subunit format.

The change to test_cli.py was required or 'make_results' was unhappy due to not having an 'options' attribute, so the tests were made more robust.

Apologies for some of the formatting changes. The trailing whitespace was automatically cleaned up by my emacs save hook (not a bad thing) and the others were me being OCD. Sorry for the somewhat bloated diff.

To post a comment you must log in.
Jonathan Lange (jml) wrote :

Hey Brad,

Thanks for submitting this. First up, no worries about the cleanups -- I'm really grateful that you took the time to do them.

We had a bit of a chat about this on IRC. Here are the highlights:

 * --subunit here only shows timestamps and failing tests, rather than the full test run. This isn't the behaviour you want.

 * Probably the right thing to do is push the call to TestResultFilter that's in load.py down into the UI make_result() method. This allows the UI to have full control over which tests are shown in the output. Note that this will probably have a bunch of annoying test fallout. My hunch is that this will make progress display easier too.

 * I think that the default for --subunit should be as for the current output: only show failing tests. testr should then grow a new option for showing full results. --full-results is as good a spelling as any.

 * Both --subunit and --full-results should be applied to both 'testr run' and 'testr load'.

 * "Output collated results" is very parallel-run specific. Should probably say, "display results in subunit format" or similar.

 * I haven't seen vars(x).get(y) before. I'm guessing this is equivalent to getattr(x, y, None)?

Thanks,
jml

review: Disapprove
Brad Crittenden (bac) wrote :

Thanks for the review Jono. I've created a new branch and merge proposal that addresses your issues. Please mark this one 'rejected'.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'testrepository/commands/run.py'
2--- testrepository/commands/run.py 2010-12-19 09:17:29 +0000
3+++ testrepository/commands/run.py 2012-04-17 14:20:23 +0000
4@@ -1,11 +1,11 @@
5 #
6-# Copyright (c) 2010 Testrepository Contributors
7-#
8+# Copyright (c) 2010-2012 Testrepository Contributors
9+#
10 # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
11 # license at the users choice. A copy of both licenses are available in the
12 # project source as Apache-2.0 and BSD. You may not use this file except in
13 # compliance with one of these two licences.
14-#
15+#
16 # Unless required by applicable law or agreed to in writing, software
17 # distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
18 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
19@@ -14,11 +14,7 @@
20
21 """Run a projects tests and load them into testrepository."""
22
23-import ConfigParser
24-from cStringIO import StringIO
25 import optparse
26-import os.path
27-import string
28
29 from testtools import TestResult
30
31@@ -39,7 +35,10 @@
32 optparse.Option("--parallel", action="store_true",
33 default=False, help="Run tests in parallel processes."),
34 optparse.Option("--partial", action="store_true",
35- default=False, help="Only some tests will be run. Implied by --failing."),
36+ default=False,
37+ help="Only some tests will be run. Implied by --failing."),
38+ optparse.Option("--subunit", action="store_true",
39+ default=False, help="Output collated results."),
40 ]
41 args = [StringArgument('testargs', 0, None)]
42 # Can be assigned to to inject a custom command factory.
43
44=== modified file 'testrepository/tests/test_ui.py'
45--- testrepository/tests/test_ui.py 2011-11-02 19:27:08 +0000
46+++ testrepository/tests/test_ui.py 2012-04-17 14:20:23 +0000
47@@ -1,11 +1,11 @@
48 #
49 # Copyright (c) 2009, 2010 Testrepository Contributors
50-#
51+#
52 # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
53 # license at the users choice. A copy of both licenses are available in the
54 # project source as Apache-2.0 and BSD. You may not use this file except in
55 # compliance with one of these two licences.
56-#
57+#
58 # Unless required by applicable law or agreed to in writing, software
59 # distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
60 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
61@@ -17,12 +17,14 @@
62 from cStringIO import StringIO
63 import optparse
64 import subprocess
65+import subunit
66 import sys
67
68 from testtools.matchers import raises
69
70 from testrepository import arguments, commands
71 from testrepository.commands import load
72+from testrepository.commands.run import run
73 from testrepository.repository import memory
74 from testrepository.ui import cli, decorator, model
75 from testrepository.tests import ResourcedTestCase
76@@ -119,7 +121,7 @@
77 # output_table shows a table.
78 ui = self.get_test_ui()
79 ui.output_table([('col1', 'col2'), ('row1c1','row1c2')])
80-
81+
82 def test_output_tests(self):
83 # output_tests can be called, and takes a list of tests to output.
84 ui = self.get_test_ui()
85@@ -228,7 +230,22 @@
86 # make_result can take a previous run.
87 ui = self.ui_factory()
88 ui.set_command(commands.Command(ui))
89- result = ui.make_result(lambda: None, memory.Repository().get_failing())
90+ result = ui.make_result(
91+ lambda: None, memory.Repository().get_failing())
92 result.startTestRun()
93 result.stopTestRun()
94 self.assertEqual(0, result.testsRun)
95+
96+
97+class TestCLIUISpecific(ResourcedTestCase):
98+
99+ def test_run_subunit_option(self):
100+ ui = cli_ui_factory(options=[('subunit', True)])
101+ ui.set_command(run)
102+ self.assertEqual(True, ui.options.subunit)
103+
104+ def test_check_result_output(self):
105+ ui = cli_ui_factory(options=[('subunit', True)])
106+ ui.set_command(run)
107+ result = ui.make_result(lambda: None)
108+ self.assertTrue(isinstance(result, subunit.TestProtocolClient))
109
110=== modified file 'testrepository/tests/ui/test_cli.py'
111--- testrepository/tests/ui/test_cli.py 2012-04-02 12:14:26 +0000
112+++ testrepository/tests/ui/test_cli.py 2012-04-17 14:20:23 +0000
113@@ -234,6 +234,7 @@
114 if stream is None:
115 stream = StringIO()
116 ui = cli.UI([], None, stream, None)
117+ ui.set_command(commands.Command(ui))
118 return ui.make_result(lambda: None)
119
120 def test_initial_stream(self):
121
122=== modified file 'testrepository/ui/cli.py'
123--- testrepository/ui/cli.py 2012-03-29 10:58:30 +0000
124+++ testrepository/ui/cli.py 2012-04-17 14:20:23 +0000
125@@ -17,6 +17,7 @@
126 from optparse import OptionParser
127 import os
128 import signal
129+import subunit
130 import sys
131
132 from testtools.compat import unicode_output_stream
133@@ -71,7 +72,11 @@
134 yield self._stdin
135
136 def make_result(self, get_id, previous_run=None):
137- return CLITestResult(self, get_id, self._stdout, previous_run)
138+ if vars(self.options).get('subunit'):
139+ results = subunit.TestProtocolClient(self._stdout)
140+ else:
141+ results = CLITestResult(self, get_id, self._stdout, previous_run)
142+ return results
143
144 def output_error(self, error_tuple):
145 self._stderr.write(str(error_tuple[1]) + '\n')

Subscribers

People subscribed via source and target branches