Merge lp:~lifeless/subunit/nopassthrough into lp:~subunit/subunit/trunk

Proposed by Robert Collins
Status: Merged
Merged at revision: not available
Proposed branch: lp:~lifeless/subunit/nopassthrough
Merge into: lp:~subunit/subunit/trunk
Diff against target: None lines
To merge this branch: bzr merge lp:~lifeless/subunit/nopassthrough
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Jonathan Lange Approve
Review via email: mp+9557@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

This adds --no-passthrough to most filers, which is useful for ensuring there is no noise in a stream. This is important for some uses, like when outputting structured data other programs will be reading.

lp:~lifeless/subunit/nopassthrough updated
76. By Robert Collins

Fix optparse sense inversion in new option.

Revision history for this message
Jonathan Lange (jml) wrote :

> This adds --no-passthrough to most filers, which is useful for ensuring there
> is no noise in a stream. This is important for some uses, like when outputting
> structured data other programs will be reading.

Hey Rob,

This seems like a good feature & I can't fault the code. From the description in the MP though, I was expecting the behaviour to be that --no-passthrough makes the script error out when there is noise.

Perhaps the option should be 'discard-noise' or something similar?

jml

review: Approve
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Other than the two space issue this seems fine to me.

Bonus points for a test that proves that only non-subunit data is written to the output stream.

review: Approve
Revision history for this message
Robert Collins (lifeless) wrote :

On Tue, 2009-08-04 at 08:53 +0000, Jonathan Lange wrote:
> Review: Approve
> > This adds --no-passthrough to most filers, which is useful for ensuring there
> > is no noise in a stream. This is important for some uses, like when outputting
> > structured data other programs will be reading.
>
> Hey Rob,
>
> This seems like a good feature & I can't fault the code. From the description in the MP though, I was expecting the behaviour to be that --no-passthrough makes the script error out when there is noise.
>
> Perhaps the option should be 'discard-noise' or something similar?

disard-passthrough perhaps?

I hesitate to call the other content 'noise' - its typically things like
'make' output, or extra debugging that faulty tests aren't capturing.

So I'd like a neutral name for it.

-Rob

Revision history for this message
Robert Collins (lifeless) wrote :

I've landed this with the current name, on the basis that we have a week or so to change it before I do a 0.2 release.

Revision history for this message
Jonathan Lange (jml) wrote :

On Wed, Aug 5, 2009 at 1:18 AM, Robert Collins<email address hidden> wrote:
> On Tue, 2009-08-04 at 08:53 +0000, Jonathan Lange wrote:
>> Review: Approve
>> > This adds --no-passthrough to most filers, which is useful for ensuring there
>> > is no noise in a stream. This is important for some uses, like when outputting
>> > structured data other programs will be reading.
>>
>> Hey Rob,
>>
>> This seems like a good feature & I can't fault the code. From the description in the MP though, I was expecting the behaviour to be that --no-passthrough makes the script error out when there is noise.
>>
>> Perhaps the option should be 'discard-noise' or something similar?
>
> disard-passthrough perhaps?
>
> I hesitate to call the other content 'noise' - its typically things like
> 'make' output, or extra debugging that faulty tests aren't capturing.
>
> So I'd like a neutral name for it.
>

I agree. I'm stumped for the right noun though.

jml

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2009-08-01 22:10:25 +0000
+++ NEWS 2009-08-02 22:55:36 +0000
@@ -10,6 +10,10 @@
1010
11 IMPROVEMENTS:11 IMPROVEMENTS:
1212
13 * A number of filters now support ``--no-passthrough`` to cause all
14 non-subunit content to be discarded. This is useful when precise control
15 over what is output is required - such as with subunit2junitxml.
16
13 * Subunit streams can now include optional, incremental lookahead17 * Subunit streams can now include optional, incremental lookahead
14 information about progress. This allows reporters to make estimates18 information about progress. This allows reporters to make estimates
15 about completion, when such information is available. See the README19 about completion, when such information is available. See the README
1620
=== modified file 'filters/subunit-filter'
--- filters/subunit-filter 2009-03-01 21:39:53 +0000
+++ filters/subunit-filter 2009-08-02 22:55:36 +0000
@@ -26,7 +26,12 @@
26import sys26import sys
27import unittest27import unittest
2828
29from subunit import ProtocolTestCase, TestResultFilter, TestProtocolClient29from subunit import (
30 DiscardStream,
31 ProtocolTestCase,
32 TestProtocolClient,
33 TestResultFilter,
34 )
3035
31parser = OptionParser(description=__doc__)36parser = OptionParser(description=__doc__)
32parser.add_option("--error", action="store_false",37parser.add_option("--error", action="store_false",
@@ -37,6 +42,8 @@
37 help="include failures", default=False, dest="failure")42 help="include failures", default=False, dest="failure")
38parser.add_option("-f", "--no-failure", action="store_true",43parser.add_option("-f", "--no-failure", action="store_true",
39 help="include failures", dest="failure")44 help="include failures", dest="failure")
45parser.add_option("--no-passthrough", action="store_true",
46 help="Hide all non subunit input.", default=True, dest="no_passthrough")
40parser.add_option("-s", "--success", action="store_false",47parser.add_option("-s", "--success", action="store_false",
41 help="include successes", dest="success")48 help="include successes", dest="success")
42parser.add_option("--no-skip", action="store_true",49parser.add_option("--no-skip", action="store_true",
@@ -45,8 +52,13 @@
45 help="exclude successes", default=True, dest="success")52 help="exclude successes", default=True, dest="success")
46(options, args) = parser.parse_args()53(options, args) = parser.parse_args()
47result = TestProtocolClient(sys.stdout)54result = TestProtocolClient(sys.stdout)
48result = TestResultFilter(result, filter_error=options.error, filter_failure=options.failure,55result = TestResultFilter(result, filter_error=options.error,
49 filter_success=options.success, filter_skip=options.skip)56 filter_failure=options.failure, filter_success=options.success,
50test = ProtocolTestCase(sys.stdin)57 filter_skip=options.skip)
58if options.no_passthrough:
59 passthrough_stream = DiscardStream()
60else:
61 passthrough_stream = None
62test = ProtocolTestCase(sys.stdin, passthrough=passthrough_stream)
51test.run(result)63test.run(result)
52sys.exit(0)64sys.exit(0)
5365
=== modified file 'filters/subunit-ls'
--- filters/subunit-ls 2009-07-20 10:12:42 +0000
+++ filters/subunit-ls 2009-08-02 22:55:36 +0000
@@ -23,7 +23,7 @@
23import sys23import sys
24import unittest24import unittest
2525
26from subunit import ProtocolTestCase26from subunit import DiscardStream, ProtocolTestCase
2727
28class TestIdPrintingResult(unittest.TestResult):28class TestIdPrintingResult(unittest.TestResult):
2929
@@ -79,9 +79,15 @@
79parser.add_option("--times", action="store_true",79parser.add_option("--times", action="store_true",
80 help="list the time each test took (requires a timestamped stream)",80 help="list the time each test took (requires a timestamped stream)",
81 default=False)81 default=False)
82parser.add_option("--no-passthrough", action="store_true",
83 help="Hide all non subunit input.", default=True, dest="no_passthrough")
82(options, args) = parser.parse_args()84(options, args) = parser.parse_args()
83result = TestIdPrintingResult(sys.stdout, options.times)85result = TestIdPrintingResult(sys.stdout, options.times)
84test = ProtocolTestCase(sys.stdin)86if options.no_passthrough:
87 passthrough_stream = DiscardStream()
88else:
89 passthrough_stream = None
90test = ProtocolTestCase(sys.stdin, passthrough=passthrough_stream)
85test.run(result)91test.run(result)
86if result.wasSuccessful():92if result.wasSuccessful():
87 exit_code = 093 exit_code = 0
8894
=== modified file 'filters/subunit-stats'
--- filters/subunit-stats 2009-02-15 11:55:00 +0000
+++ filters/subunit-stats 2009-08-02 22:55:36 +0000
@@ -19,13 +19,22 @@
1919
20"""Filter a subunit stream to get aggregate statistics."""20"""Filter a subunit stream to get aggregate statistics."""
2121
22from optparse import OptionParser
22import sys23import sys
23import unittest24import unittest
2425
25from subunit import ProtocolTestCase, TestResultStats26from subunit import DiscardStream, ProtocolTestCase, TestResultStats
2627
28parser = OptionParser(description=__doc__)
29parser.add_option("--no-passthrough", action="store_true",
30 help="Hide all non subunit input.", default=True, dest="no_passthrough")
31(options, args) = parser.parse_args()
27result = TestResultStats(sys.stdout)32result = TestResultStats(sys.stdout)
28test = ProtocolTestCase(sys.stdin)33if options.no_passthrough:
34 passthrough_stream = DiscardStream()
35else:
36 passthrough_stream = None
37test = ProtocolTestCase(sys.stdin, passthrough=passthrough_stream)
29test.run(result)38test.run(result)
30result.formatStats()39result.formatStats()
31if result.wasSuccessful():40if result.wasSuccessful():
3241
=== modified file 'filters/subunit2junitxml'
--- filters/subunit2junitxml 2009-08-01 08:01:27 +0000
+++ filters/subunit2junitxml 2009-08-02 22:55:36 +0000
@@ -19,10 +19,11 @@
1919
20"""Filter a subunit stream to get aggregate statistics."""20"""Filter a subunit stream to get aggregate statistics."""
2121
22from optparse import OptionParser
22import sys23import sys
23import unittest24import unittest
2425
25from subunit import ProtocolTestCase26from subunit import DiscardStream, ProtocolTestCase
26try:27try:
27 from junitxml import JUnitXmlResult28 from junitxml import JUnitXmlResult
28except ImportError:29except ImportError:
@@ -30,8 +31,16 @@
30 "http://pypi.python.org/pypi/junitxml) is required for this filter.")31 "http://pypi.python.org/pypi/junitxml) is required for this filter.")
31 raise32 raise
3233
34parser = OptionParser(description=__doc__)
35parser.add_option("--no-passthrough", action="store_true",
36 help="Hide all non subunit input.", default=True, dest="no_passthrough")
37(options, args) = parser.parse_args()
33result = JUnitXmlResult(sys.stdout)38result = JUnitXmlResult(sys.stdout)
34test = ProtocolTestCase(sys.stdin)39if options.no_passthrough:
40 passthrough_stream = DiscardStream()
41else:
42 passthrough_stream = None
43test = ProtocolTestCase(sys.stdin, passthrough=passthrough_stream)
35result.startTestRun()44result.startTestRun()
36test.run(result)45test.run(result)
37result.stopTestRun()46result.stopTestRun()
3847
=== modified file 'filters/subunit2pyunit'
--- filters/subunit2pyunit 2009-07-28 21:44:28 +0000
+++ filters/subunit2pyunit 2009-08-02 22:55:36 +0000
@@ -23,14 +23,20 @@
23import sys23import sys
24import unittest24import unittest
2525
26from subunit import ProtocolTestCase, TestProtocolServer26from subunit import DiscardStream, ProtocolTestCase, TestProtocolServer
2727
28parser = OptionParser(description=__doc__)28parser = OptionParser(description=__doc__)
29parser.add_option("--no-passthrough", action="store_true",
30 help="Hide all non subunit input.", default=True, dest="no_passthrough")
29parser.add_option("--progress", action="store_true",31parser.add_option("--progress", action="store_true",
30 help="Use bzrlib's test reporter (requires bzrlib)",32 help="Use bzrlib's test reporter (requires bzrlib)",
31 default=False)33 default=False)
32(options, args) = parser.parse_args()34(options, args) = parser.parse_args()
33test = ProtocolTestCase(sys.stdin)35if options.no_passthrough:
36 passthrough_stream = DiscardStream()
37else:
38 passthrough_stream = None
39test = ProtocolTestCase(sys.stdin, passthrough=passthrough_stream)
34if options.progress:40if options.progress:
35 from bzrlib.tests import TextTestRunner41 from bzrlib.tests import TextTestRunner
36 from bzrlib import ui42 from bzrlib import ui
3743
=== modified file 'python/subunit/__init__.py'
--- python/subunit/__init__.py 2009-07-28 13:32:10 +0000
+++ python/subunit/__init__.py 2009-08-02 22:55:36 +0000
@@ -63,6 +63,13 @@
63 return new_tags, gone_tags63 return new_tags, gone_tags
6464
6565
66class DiscardStream(object):
67 """A filelike object which discards what is written to it."""
68
69 def write(self, bytes):
70 pass
71
72
66class TestProtocolServer(object):73class TestProtocolServer(object):
67 """A class for receiving results from a TestProtocol client.74 """A class for receiving results from a TestProtocol client.
68 75
@@ -77,19 +84,19 @@
77 READING_XFAIL = 584 READING_XFAIL = 5
78 READING_SUCCESS = 685 READING_SUCCESS = 6
7986
80 def __init__(self, client, stream=sys.stdout):87 def __init__(self, client, stream=None):
81 """Create a TestProtocol server instance.88 """Create a TestProtocol server instance.
8289
83 client should be an object that provides90 :param client: An object meeting the unittest.TestResult protocol.
84 - startTest91 :param stream: The stream that lines received which are not part of the
85 - addSuccess92 subunit protocol should be written to. This allows custom handling
86 - addFailure93 of mixed protocols. By default, sys.stdout will be used for
87 - addError94 convenience.
88 - stopTest
89 methods, i.e. a TestResult.
90 """95 """
91 self.state = TestProtocolServer.OUTSIDE_TEST96 self.state = TestProtocolServer.OUTSIDE_TEST
92 self.client = client97 self.client = client
98 if stream is None:
99 stream = sys.stdout
93 self._stream = stream100 self._stream = stream
94 self.tags = set()101 self.tags = set()
95102
@@ -701,8 +708,16 @@
701class ProtocolTestCase(object):708class ProtocolTestCase(object):
702 """A test case which reports a subunit stream."""709 """A test case which reports a subunit stream."""
703710
704 def __init__(self, stream):711 def __init__(self, stream, passthrough=None):
712 """Create a ProtocolTestCase reading from stream.
713
714 :param stream: A filelike object which a subunit stream can be read
715 from.
716 :param passthrough: A stream pass non subunit input on to. If not
717 supplied, the TestProtocolServer default is used.
718 """
705 self._stream = stream719 self._stream = stream
720 self._passthrough = passthrough
706721
707 def __call__(self, result=None):722 def __call__(self, result=None):
708 return self.run(result)723 return self.run(result)
@@ -710,7 +725,7 @@
710 def run(self, result=None):725 def run(self, result=None):
711 if result is None:726 if result is None:
712 result = self.defaultTestResult()727 result = self.defaultTestResult()
713 protocol = TestProtocolServer(result)728 protocol = TestProtocolServer(result, self._passthrough)
714 line = self._stream.readline()729 line = self._stream.readline()
715 while line:730 while line:
716 protocol.lineReceived(line)731 protocol.lineReceived(line)
717732
=== modified file 'python/subunit/tests/test_test_protocol.py'
--- python/subunit/tests/test_test_protocol.py 2009-07-28 13:32:10 +0000
+++ python/subunit/tests/test_test_protocol.py 2009-08-02 22:55:36 +0000
@@ -131,6 +131,7 @@
131class TestTestImports(unittest.TestCase):131class TestTestImports(unittest.TestCase):
132132
133 def test_imports(self):133 def test_imports(self):
134 from subunit import DiscardStream
134 from subunit import TestProtocolServer135 from subunit import TestProtocolServer
135 from subunit import RemotedTestCase136 from subunit import RemotedTestCase
136 from subunit import RemoteError137 from subunit import RemoteError
@@ -139,6 +140,12 @@
139 from subunit import TestProtocolClient140 from subunit import TestProtocolClient
140141
141142
143class TestDiscardStream(unittest.TestCase):
144
145 def test_write(self):
146 subunit.DiscardStream().write("content")
147
148
142class TestTestProtocolServerPipe(unittest.TestCase):149class TestTestProtocolServerPipe(unittest.TestCase):
143150
144 def test_story(self):151 def test_story(self):
@@ -194,7 +201,6 @@
194class TestTestProtocolServerPassThrough(unittest.TestCase):201class TestTestProtocolServerPassThrough(unittest.TestCase):
195202
196 def setUp(self):203 def setUp(self):
197 from StringIO import StringIO
198 self.stdout = StringIO()204 self.stdout = StringIO()
199 self.test = subunit.RemotedTestCase("old mcdonald")205 self.test = subunit.RemotedTestCase("old mcdonald")
200 self.client = MockTestProtocolServerClient()206 self.client = MockTestProtocolServerClient()

Subscribers

People subscribed via source and target branches