Merge lp:~jml/subunit/move-ls into lp:~subunit/subunit/trunk

Proposed by Jonathan Lange
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 134
Merged at revision: 132
Proposed branch: lp:~jml/subunit/move-ls
Merge into: lp:~subunit/subunit/trunk
Diff against target: 214 lines (+63/-64)
2 files modified
filters/subunit-ls (+1/-50)
python/subunit/test_results.py (+62/-14)
To merge this branch: bzr merge lp:~jml/subunit/move-ls
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+31769@code.launchpad.net

Commit message

Move subunit-ls guts into subunit.test_results

Description of the change

This moves the code with the logic for subunit-ls out of the binary and into subunit.test_results, where it can be imported from and re-used in other Python applications.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'filters/subunit-ls'
2--- filters/subunit-ls 2009-09-30 12:04:18 +0000
3+++ filters/subunit-ls 2010-08-04 17:10:55 +0000
4@@ -18,58 +18,9 @@
5
6 from optparse import OptionParser
7 import sys
8-import unittest
9
10 from subunit import DiscardStream, ProtocolTestCase
11-
12-class TestIdPrintingResult(unittest.TestResult):
13-
14- def __init__(self, stream, show_times=False):
15- """Create a FilterResult object outputting to stream."""
16- unittest.TestResult.__init__(self)
17- self._stream = stream
18- self.failed_tests = 0
19- self.__time = 0
20- self.show_times = show_times
21- self._test = None
22- self._test_duration = 0
23-
24- def addError(self, test, err):
25- self.failed_tests += 1
26- self._test = test
27-
28- def addFailure(self, test, err):
29- self.failed_tests += 1
30- self._test = test
31-
32- def addSuccess(self, test):
33- self._test = test
34-
35- def reportTest(self, test, duration):
36- if self.show_times:
37- seconds = duration.seconds
38- seconds += duration.days * 3600 * 24
39- seconds += duration.microseconds / 1000000.0
40- self._stream.write(test.id() + ' %0.3f\n' % seconds)
41- else:
42- self._stream.write(test.id() + '\n')
43-
44- def startTest(self, test):
45- self._start_time = self._time()
46-
47- def stopTest(self, test):
48- test_duration = self._time() - self._start_time
49- self.reportTest(self._test, test_duration)
50-
51- def time(self, time):
52- self.__time = time
53-
54- def _time(self):
55- return self.__time
56-
57- def wasSuccessful(self):
58- "Tells whether or not this result was a success"
59- return self.failed_tests == 0
60+from subunit.test_results import TestIdPrintingResult
61
62
63 parser = OptionParser(description=__doc__)
64
65=== modified file 'python/subunit/test_results.py'
66--- python/subunit/test_results.py 2010-03-11 21:12:10 +0000
67+++ python/subunit/test_results.py 2010-08-04 17:10:55 +0000
68@@ -6,7 +6,7 @@
69 # license at the users choice. A copy of both licenses are available in the
70 # project source as Apache-2.0 and BSD. You may not use this file except in
71 # compliance with one of these two licences.
72-#
73+#
74 # Unless required by applicable law or agreed to in writing, software
75 # distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
76 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
77@@ -21,16 +21,14 @@
78 import iso8601
79 import testtools
80
81-import subunit
82-
83
84 # NOT a TestResult, because we are implementing the interface, not inheriting
85 # it.
86 class TestResultDecorator(object):
87 """General pass-through decorator.
88
89- This provides a base that other TestResults can inherit from to
90- gain basic forwarding functionality. It also takes care of
91+ This provides a base that other TestResults can inherit from to
92+ gain basic forwarding functionality. It also takes care of
93 handling the case where the target doesn't support newer methods
94 or features by degrading them.
95 """
96@@ -201,11 +199,11 @@
97 """A pyunit TestResult interface implementation which filters tests.
98
99 Tests that pass the filter are handed on to another TestResult instance
100- for further processing/reporting. To obtain the filtered results,
101+ for further processing/reporting. To obtain the filtered results,
102 the other instance must be interrogated.
103
104 :ivar result: The result that tests are passed to after filtering.
105- :ivar filter_predicate: The callback run to decide whether to pass
106+ :ivar filter_predicate: The callback run to decide whether to pass
107 a result.
108 """
109
110@@ -213,7 +211,7 @@
111 filter_success=True, filter_skip=False,
112 filter_predicate=None):
113 """Create a FilterResult object filtering to result.
114-
115+
116 :param filter_error: Filter out errors.
117 :param filter_failure: Filter out failures.
118 :param filter_success: Filter out successful tests.
119@@ -238,9 +236,9 @@
120 self._current_test_filtered = None
121 # The (new, gone) tags for the current test.
122 self._current_test_tags = None
123-
124+
125 def addError(self, test, err=None, details=None):
126- if (not self._filter_error and
127+ if (not self._filter_error and
128 self.filter_predicate(test, 'error', err, details)):
129 self.decorated.startTest(test)
130 self.decorated.addError(test, err, details=details)
131@@ -288,17 +286,17 @@
132
133 def startTest(self, test):
134 """Start a test.
135-
136+
137 Not directly passed to the client, but used for handling of tags
138 correctly.
139 """
140 self._current_test = test
141 self._current_test_filtered = False
142 self._current_test_tags = set(), set()
143-
144+
145 def stopTest(self, test):
146 """Stop a test.
147-
148+
149 Not directly passed to the client, but used for handling of tags
150 correctly.
151 """
152@@ -316,7 +314,7 @@
153
154 Adds and removes tags as appropriate. If a test is currently running,
155 tags are not affected for subsequent tests.
156-
157+
158 :param new_tags: Tags to add,
159 :param gone_tags: Tags to remove.
160 """
161@@ -332,3 +330,53 @@
162 if id.startswith("subunit.RemotedTestCase."):
163 return id[len("subunit.RemotedTestCase."):]
164 return id
165+
166+
167+class TestIdPrintingResult(testtools.TestResult):
168+
169+ def __init__(self, stream, show_times=False):
170+ """Create a FilterResult object outputting to stream."""
171+ testtools.TestResult.__init__(self)
172+ self._stream = stream
173+ self.failed_tests = 0
174+ self.__time = 0
175+ self.show_times = show_times
176+ self._test = None
177+ self._test_duration = 0
178+
179+ def addError(self, test, err):
180+ self.failed_tests += 1
181+ self._test = test
182+
183+ def addFailure(self, test, err):
184+ self.failed_tests += 1
185+ self._test = test
186+
187+ def addSuccess(self, test):
188+ self._test = test
189+
190+ def reportTest(self, test, duration):
191+ if self.show_times:
192+ seconds = duration.seconds
193+ seconds += duration.days * 3600 * 24
194+ seconds += duration.microseconds / 1000000.0
195+ self._stream.write(test.id() + ' %0.3f\n' % seconds)
196+ else:
197+ self._stream.write(test.id() + '\n')
198+
199+ def startTest(self, test):
200+ self._start_time = self._time()
201+
202+ def stopTest(self, test):
203+ test_duration = self._time() - self._start_time
204+ self.reportTest(self._test, test_duration)
205+
206+ def time(self, time):
207+ self.__time = time
208+
209+ def _time(self):
210+ return self.__time
211+
212+ def wasSuccessful(self):
213+ "Tells whether or not this result was a success"
214+ return self.failed_tests == 0

Subscribers

People subscribed via source and target branches