Merge lp:~jelmer/brz/python3-selftest into lp:brz
- python3-selftest
- Merge into trunk
Proposed by
Jelmer Vernooij
Status: | Merged |
---|---|
Approved by: | Jelmer Vernooij |
Approved revision: | no longer in the source branch. |
Merge reported by: | The Breezy Bot |
Merged at revision: | not available |
Proposed branch: | lp:~jelmer/brz/python3-selftest |
Merge into: | lp:brz |
Diff against target: |
347 lines (+86/-55) 2 files modified
breezy/tests/test_selftest.py (+64/-51) python3.passing (+22/-4) |
To merge this branch: | bzr merge lp:~jelmer/brz/python3-selftest |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Martin Packman | Approve | ||
Review via email: mp+353202@code.launchpad.net |
Commit message
Fix most selftest tests on Python 3.
Description of the change
Fix most selftest tests on Python 3.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'breezy/tests/test_selftest.py' |
2 | --- breezy/tests/test_selftest.py 2018-08-02 23:52:07 +0000 |
3 | +++ breezy/tests/test_selftest.py 2018-08-15 21:13:21 +0000 |
4 | @@ -19,6 +19,7 @@ |
5 | import gc |
6 | import doctest |
7 | from functools import reduce |
8 | +from io import BytesIO, TextIOWrapper |
9 | import os |
10 | import signal |
11 | import sys |
12 | @@ -1260,16 +1261,21 @@ |
13 | def test_log_unicode(self): |
14 | self.log(u"\u2606") |
15 | self.fail("Now print that log!") |
16 | - out = StringIO() |
17 | + if PY3: |
18 | + bio = BytesIO() |
19 | + out = TextIOWrapper(bio, 'ascii', 'backslashreplace') |
20 | + else: |
21 | + bio = out = StringIO() |
22 | self.overrideAttr(osutils, "get_terminal_encoding", |
23 | lambda trace=False: "ascii") |
24 | result = self.run_test_runner(tests.TextTestRunner(stream=out), |
25 | FailureWithUnicode("test_log_unicode")) |
26 | - self.assertContainsRe(out.getvalue(), |
27 | - "(?:Text attachment: )?log" |
28 | - "(?:\n-+\n|: {{{)" |
29 | - "\\d+\\.\\d+ \\\\u2606" |
30 | - "(?:\n-+\n|}}}\n)") |
31 | + out.flush() |
32 | + self.assertContainsRe(bio.getvalue(), |
33 | + b"(?:Text attachment: )?log" |
34 | + b"(?:\n-+\n|: {{{)" |
35 | + b"\\d+\\.\\d+ \\\\u2606" |
36 | + b"(?:\n-+\n|}}}\n)") |
37 | |
38 | |
39 | class SampleTestCase(tests.TestCase): |
40 | @@ -2045,7 +2051,11 @@ |
41 | |
42 | def run_selftest(self, **kwargs): |
43 | """Run selftest returning its output.""" |
44 | - output = StringIO() |
45 | + if PY3: |
46 | + bio = BytesIO() |
47 | + output = TextIOWrapper(bio, 'utf-8') |
48 | + else: |
49 | + bio = output = StringIO() |
50 | old_transport = breezy.tests.default_transport |
51 | old_root = tests.TestCaseWithMemoryTransport.TEST_ROOT |
52 | tests.TestCaseWithMemoryTransport.TEST_ROOT = None |
53 | @@ -2054,8 +2064,11 @@ |
54 | finally: |
55 | breezy.tests.default_transport = old_transport |
56 | tests.TestCaseWithMemoryTransport.TEST_ROOT = old_root |
57 | - output.seek(0) |
58 | - return output |
59 | + if PY3: |
60 | + output.flush() |
61 | + output.detach() |
62 | + bio.seek(0) |
63 | + return bio |
64 | |
65 | |
66 | class TestSelftest(tests.TestCase, SelfTestHelper): |
67 | @@ -2075,11 +2088,13 @@ |
68 | def factory(self): |
69 | """A test suite factory.""" |
70 | class Test(tests.TestCase): |
71 | + def id(self): |
72 | + return __name__ + ".Test." + self._testMethodName |
73 | def a(self): |
74 | pass |
75 | def b(self): |
76 | pass |
77 | - def c(self): |
78 | + def c(telf): |
79 | pass |
80 | return TestUtil.TestSuite([Test("a"), Test("b"), Test("c")]) |
81 | |
82 | @@ -2091,13 +2106,13 @@ |
83 | def test_list_only_filtered(self): |
84 | output = self.run_selftest(test_suite_factory=self.factory, |
85 | list_only=True, pattern="Test.b") |
86 | - self.assertEndsWith(output.getvalue(), "Test.b\n") |
87 | + self.assertEndsWith(output.getvalue(), b"Test.b\n") |
88 | self.assertLength(1, output.readlines()) |
89 | |
90 | def test_list_only_excludes(self): |
91 | output = self.run_selftest(test_suite_factory=self.factory, |
92 | list_only=True, exclude_pattern="Test.b") |
93 | - self.assertNotContainsRe("Test.b", output.getvalue()) |
94 | + self.assertNotContainsRe(b"Test.b", output.getvalue()) |
95 | self.assertLength(2, output.readlines()) |
96 | |
97 | def test_lsprof_tests(self): |
98 | @@ -2148,7 +2163,7 @@ |
99 | output = self.run_selftest(test_suite_factory=self.factory, |
100 | starting_with=['breezy.tests.test_selftest.Test.a'], |
101 | list_only=True) |
102 | - self.assertEqual('breezy.tests.test_selftest.Test.a\n', |
103 | + self.assertEqual(b'breezy.tests.test_selftest.Test.a\n', |
104 | output.getvalue()) |
105 | |
106 | def test_starting_with_multiple_argument(self): |
107 | @@ -2156,8 +2171,8 @@ |
108 | starting_with=['breezy.tests.test_selftest.Test.a', |
109 | 'breezy.tests.test_selftest.Test.b'], |
110 | list_only=True) |
111 | - self.assertEqual('breezy.tests.test_selftest.Test.a\n' |
112 | - 'breezy.tests.test_selftest.Test.b\n', |
113 | + self.assertEqual(b'breezy.tests.test_selftest.Test.a\n' |
114 | + b'breezy.tests.test_selftest.Test.b\n', |
115 | output.getvalue()) |
116 | |
117 | def check_transport_set(self, transport_server): |
118 | @@ -2186,7 +2201,7 @@ |
119 | |
120 | def test_load_list(self): |
121 | # Provide a list with one test - this test. |
122 | - test_id_line = '%s\n' % self.id() |
123 | + test_id_line = b'%s\n' % self.id().encode('ascii') |
124 | self.build_tree_contents([('test.list', test_id_line)]) |
125 | # And generate a list of the tests in the suite. |
126 | stream = self.run_selftest(load_list='test.list', list_only=True) |
127 | @@ -2219,18 +2234,18 @@ |
128 | def test_fail_has_log(self): |
129 | content, result = self.run_subunit_stream('test_fail') |
130 | self.assertEqual(1, len(result.failures)) |
131 | - self.assertContainsRe(content, '(?m)^log$') |
132 | - self.assertContainsRe(content, 'this test will fail') |
133 | + self.assertContainsRe(content, b'(?m)^log$') |
134 | + self.assertContainsRe(content, b'this test will fail') |
135 | |
136 | def test_error_has_log(self): |
137 | content, result = self.run_subunit_stream('test_error') |
138 | - self.assertContainsRe(content, '(?m)^log$') |
139 | - self.assertContainsRe(content, 'this test errored') |
140 | + self.assertContainsRe(content, b'(?m)^log$') |
141 | + self.assertContainsRe(content, b'this test errored') |
142 | |
143 | def test_skip_has_no_log(self): |
144 | content, result = self.run_subunit_stream('test_skip') |
145 | - self.assertNotContainsRe(content, '(?m)^log$') |
146 | - self.assertNotContainsRe(content, 'this test will be skipped') |
147 | + self.assertNotContainsRe(content, b'(?m)^log$') |
148 | + self.assertNotContainsRe(content, b'this test will be skipped') |
149 | reasons = _get_skip_reasons(result) |
150 | self.assertEqual({'reason'}, set(reasons)) |
151 | skips = reasons['reason'] |
152 | @@ -2241,8 +2256,8 @@ |
153 | |
154 | def test_missing_feature_has_no_log(self): |
155 | content, result = self.run_subunit_stream('test_missing_feature') |
156 | - self.assertNotContainsRe(content, '(?m)^log$') |
157 | - self.assertNotContainsRe(content, 'missing the feature') |
158 | + self.assertNotContainsRe(content, b'(?m)^log$') |
159 | + self.assertNotContainsRe(content, b'missing the feature') |
160 | reasons = _get_skip_reasons(result) |
161 | self.assertEqual({'_MissingFeature\n'}, set(reasons)) |
162 | skips = reasons['_MissingFeature\n'] |
163 | @@ -2253,8 +2268,8 @@ |
164 | |
165 | def test_xfail_has_no_log(self): |
166 | content, result = self.run_subunit_stream('test_xfail') |
167 | - self.assertNotContainsRe(content, '(?m)^log$') |
168 | - self.assertNotContainsRe(content, 'test with expected failure') |
169 | + self.assertNotContainsRe(content, b'(?m)^log$') |
170 | + self.assertNotContainsRe(content, b'test with expected failure') |
171 | self.assertEqual(1, len(result.expectedFailures)) |
172 | result_content = result.expectedFailures[0][1] |
173 | self.assertNotContainsRe(result_content, |
174 | @@ -2263,15 +2278,8 @@ |
175 | |
176 | def test_unexpected_success_has_log(self): |
177 | content, result = self.run_subunit_stream('test_unexpected_success') |
178 | - self.assertContainsRe(content, '(?m)^log$') |
179 | - self.assertContainsRe(content, 'test with unexpected success') |
180 | - # GZ 2011-05-18: Old versions of subunit treat unexpected success as a |
181 | - # success, if a min version check is added remove this |
182 | - from subunit import TestProtocolClient as _Client |
183 | - if _Client.addUnexpectedSuccess.__func__ is _Client.addSuccess.__func__: |
184 | - self.expectFailure('subunit treats "unexpectedSuccess"' |
185 | - ' as a plain success', |
186 | - self.assertEqual, 1, len(result.unexpectedSuccesses)) |
187 | + self.assertContainsRe(content, b'(?m)^log$') |
188 | + self.assertContainsRe(content, b'test with unexpected success') |
189 | self.assertEqual(1, len(result.unexpectedSuccesses)) |
190 | test = result.unexpectedSuccesses[0] |
191 | # RemotedTestCase doesn't preserve the "details" |
192 | @@ -2280,8 +2288,8 @@ |
193 | def test_success_has_no_log(self): |
194 | content, result = self.run_subunit_stream('test_success') |
195 | self.assertEqual(1, result.testsRun) |
196 | - self.assertNotContainsRe(content, '(?m)^log$') |
197 | - self.assertNotContainsRe(content, 'this test succeeds') |
198 | + self.assertNotContainsRe(content, b'(?m)^log$') |
199 | + self.assertNotContainsRe(content, b'this test succeeds') |
200 | |
201 | |
202 | class TestRunBzr(tests.TestCase): |
203 | @@ -3391,10 +3399,15 @@ |
204 | """To be overridden by subclasses that run tests out of process""" |
205 | |
206 | def _run_selftest(self, **kwargs): |
207 | - sio = StringIO() |
208 | + if PY3: |
209 | + bio = BytesIO() |
210 | + sio = TextIOWrapper(bio, 'utf-8') |
211 | + else: |
212 | + sio = bio = StringIO() |
213 | self._inject_stream_into_subunit(sio) |
214 | tests.selftest(stream=sio, stop_on_failure=False, **kwargs) |
215 | - return sio.getvalue() |
216 | + sio.flush() |
217 | + return bio.getvalue() |
218 | |
219 | |
220 | class _ForkedSelftest(_Selftest): |
221 | @@ -3440,13 +3453,13 @@ |
222 | # together due to the way subunit parses and forwards the streams, |
223 | # so permit extra lines between each part of the error output. |
224 | self.assertContainsRe(out, |
225 | - "Traceback.*:\n" |
226 | - "(?:.*\n)*" |
227 | - ".+ in fork_for_tests\n" |
228 | - "(?:.*\n)*" |
229 | - "\\s*workaround_zealous_crypto_random\\(\\)\n" |
230 | - "(?:.*\n)*" |
231 | - "TypeError:") |
232 | + b"Traceback.*:\n" |
233 | + b"(?:.*\n)*" |
234 | + b".+ in fork_for_tests\n" |
235 | + b"(?:.*\n)*" |
236 | + b"\\s*workaround_zealous_crypto_random\\(\\)\n" |
237 | + b"(?:.*\n)*" |
238 | + b"TypeError:") |
239 | |
240 | |
241 | class TestUncollectedWarnings(_Selftest, tests.TestCase): |
242 | @@ -3480,8 +3493,8 @@ |
243 | if gc_on: |
244 | gc.enable() |
245 | tests.selftest_debug_flags = old_flags |
246 | - self.assertNotContainsRe(output, "Uncollected test case.*test_pass") |
247 | - self.assertContainsRe(output, "Uncollected test case.*test_self_ref") |
248 | + self.assertNotContainsRe(output, b"Uncollected test case.*test_pass") |
249 | + self.assertContainsRe(output, b"Uncollected test case.*test_self_ref") |
250 | return output |
251 | |
252 | def test_testsuite(self): |
253 | @@ -3489,11 +3502,11 @@ |
254 | |
255 | def test_pattern(self): |
256 | out = self._run_selftest_with_suite(pattern="test_(?:pass|self_ref)$") |
257 | - self.assertNotContainsRe(out, "test_skip") |
258 | + self.assertNotContainsRe(out, b"test_skip") |
259 | |
260 | def test_exclude_pattern(self): |
261 | out = self._run_selftest_with_suite(exclude_pattern="test_skip$") |
262 | - self.assertNotContainsRe(out, "test_skip") |
263 | + self.assertNotContainsRe(out, b"test_skip") |
264 | |
265 | def test_random_seed(self): |
266 | self._run_selftest_with_suite(random_seed="now") |
267 | @@ -3505,7 +3518,7 @@ |
268 | def test_starting_with_and_exclude(self): |
269 | out = self._run_selftest_with_suite(starting_with=["bt."], |
270 | exclude_pattern="test_skip$") |
271 | - self.assertNotContainsRe(out, "test_skip") |
272 | + self.assertNotContainsRe(out, b"test_skip") |
273 | |
274 | def test_additonal_decorator(self): |
275 | out = self._run_selftest_with_suite( |
276 | |
277 | === modified file 'python3.passing' |
278 | --- python3.passing 2018-08-08 02:10:06 +0000 |
279 | +++ python3.passing 2018-08-15 21:13:21 +0000 |
280 | @@ -9130,16 +9130,16 @@ |
281 | breezy.tests.per_repository_reference.test_get_record_stream.TestGetRecordStream.test_ordered_no_closure(RemoteRepositoryFormat-v2) |
282 | breezy.tests.per_repository_reference.test_get_record_stream.TestGetRecordStream.test_ordered_no_closure(RepositoryFormat2a) |
283 | breezy.tests.per_repository_reference.test_get_record_stream.TestGetRecordStream.test_ordered_no_closure(RepositoryFormat2aSubtree) |
284 | -breezy.tests.per_repository_reference.test_get_record_stream.TestGetRecordStream.test_unordered_fetch_complex_split(RemoteRepositoryFormat-default) |
285 | -breezy.tests.per_repository_reference.test_get_record_stream.TestGetRecordStream.test_unordered_fetch_complex_split(RemoteRepositoryFormat-v2) |
286 | -breezy.tests.per_repository_reference.test_get_record_stream.TestGetRecordStream.test_unordered_fetch_complex_split(RepositoryFormat2a) |
287 | -breezy.tests.per_repository_reference.test_get_record_stream.TestGetRecordStream.test_unordered_fetch_complex_split(RepositoryFormat2aSubtree) |
288 | breezy.tests.per_repository_reference.test_get_record_stream.TestGetRecordStream.test_ordered_no_closure(RepositoryFormatKnitPack5) |
289 | breezy.tests.per_repository_reference.test_get_record_stream.TestGetRecordStream.test_ordered_no_closure(RepositoryFormatKnitPack5RichRoot) |
290 | breezy.tests.per_repository_reference.test_get_record_stream.TestGetRecordStream.test_ordered_no_closure(RepositoryFormatKnitPack5RichRootBroken) |
291 | breezy.tests.per_repository_reference.test_get_record_stream.TestGetRecordStream.test_ordered_no_closure(RepositoryFormatKnitPack6) |
292 | breezy.tests.per_repository_reference.test_get_record_stream.TestGetRecordStream.test_ordered_no_closure(RepositoryFormatKnitPack6RichRoot) |
293 | breezy.tests.per_repository_reference.test_get_record_stream.TestGetRecordStream.test_ordered_no_closure(RepositoryFormatPackDevelopment2Subtree) |
294 | +breezy.tests.per_repository_reference.test_get_record_stream.TestGetRecordStream.test_unordered_fetch_complex_split(RemoteRepositoryFormat-default) |
295 | +breezy.tests.per_repository_reference.test_get_record_stream.TestGetRecordStream.test_unordered_fetch_complex_split(RemoteRepositoryFormat-v2) |
296 | +breezy.tests.per_repository_reference.test_get_record_stream.TestGetRecordStream.test_unordered_fetch_complex_split(RepositoryFormat2a) |
297 | +breezy.tests.per_repository_reference.test_get_record_stream.TestGetRecordStream.test_unordered_fetch_complex_split(RepositoryFormat2aSubtree) |
298 | breezy.tests.per_repository_reference.test_get_record_stream.TestGetRecordStream.test_unordered_fetch_complex_split(RepositoryFormatKnitPack5) |
299 | breezy.tests.per_repository_reference.test_get_record_stream.TestGetRecordStream.test_unordered_fetch_complex_split(RepositoryFormatKnitPack5RichRoot) |
300 | breezy.tests.per_repository_reference.test_get_record_stream.TestGetRecordStream.test_unordered_fetch_complex_split(RepositoryFormatKnitPack5RichRootBroken) |
301 | @@ -28221,6 +28221,7 @@ |
302 | breezy.tests.test_selftest.TestRunner.test_startTestRun |
303 | breezy.tests.test_selftest.TestRunner.test_stopTestRun |
304 | breezy.tests.test_selftest.TestRunner.test_unexpected_success_bad |
305 | +breezy.tests.test_selftest.TestRunner.test_unicode_test_output_on_ascii_stream |
306 | breezy.tests.test_selftest.TestRunner.test_unsupported_features_listed |
307 | breezy.tests.test_selftest.TestRunner.test_verbose_test_count |
308 | breezy.tests.test_selftest.TestRunSuite.test_runner_class |
309 | @@ -28247,7 +28248,10 @@ |
310 | breezy.tests.test_selftest.TestSelftest.test_lsprof_tests |
311 | breezy.tests.test_selftest.TestSelftest.test_random |
312 | breezy.tests.test_selftest.TestSelftest.test_random_reuse_is_same_order |
313 | +breezy.tests.test_selftest.TestSelftest.test_runner_class |
314 | breezy.tests.test_selftest.TestSelftest.test_selftest_benchmark_parameter_invokes_test_suite__benchmark__ |
315 | +breezy.tests.test_selftest.TestSelftest.test_starting_with_multiple_argument |
316 | +breezy.tests.test_selftest.TestSelftest.test_starting_with_single_argument |
317 | breezy.tests.test_selftest.TestSelftest.test_transport_memory |
318 | breezy.tests.test_selftest.TestSelftest.test_transport_sftp |
319 | breezy.tests.test_selftest.TestSelftestWithIdList.test_load_list |
320 | @@ -28259,6 +28263,13 @@ |
321 | breezy.tests.test_selftest.TestStartBzrSubProcess.test_run_bzr_subprocess_no_plugins |
322 | breezy.tests.test_selftest.TestStartBzrSubProcess.test_set_env |
323 | breezy.tests.test_selftest.TestStartBzrSubProcess.test_working_dir |
324 | +breezy.tests.test_selftest.TestSubunitLogDetails.test_error_has_log |
325 | +breezy.tests.test_selftest.TestSubunitLogDetails.test_fail_has_log |
326 | +breezy.tests.test_selftest.TestSubunitLogDetails.test_missing_feature_has_no_log |
327 | +breezy.tests.test_selftest.TestSubunitLogDetails.test_skip_has_no_log |
328 | +breezy.tests.test_selftest.TestSubunitLogDetails.test_success_has_no_log |
329 | +breezy.tests.test_selftest.TestSubunitLogDetails.test_unexpected_success_has_log |
330 | +breezy.tests.test_selftest.TestSubunitLogDetails.test_xfail_has_no_log |
331 | breezy.tests.test_selftest.TestTestCaseInTempDir.test_assertEqualStat_equal |
332 | breezy.tests.test_selftest.TestTestCaseInTempDir.test_assertEqualStat_notequal |
333 | breezy.tests.test_selftest.TestTestCaseInTempDir.test_assertPathExists |
334 | @@ -28368,6 +28379,13 @@ |
335 | breezy.tests.test_selftest.TestUncollectedWarningsForked.test_random_seed |
336 | breezy.tests.test_selftest.TestUncollectedWarningsForked.test_starting_with_and_exclude |
337 | breezy.tests.test_selftest.TestUncollectedWarningsForked.test_testsuite |
338 | +breezy.tests.test_selftest.TestUncollectedWarningsSubunit.test_additonal_decorator |
339 | +breezy.tests.test_selftest.TestUncollectedWarningsSubunit.test_exclude_pattern |
340 | +breezy.tests.test_selftest.TestUncollectedWarningsSubunit.test_matching_tests_first |
341 | +breezy.tests.test_selftest.TestUncollectedWarningsSubunit.test_pattern |
342 | +breezy.tests.test_selftest.TestUncollectedWarningsSubunit.test_random_seed |
343 | +breezy.tests.test_selftest.TestUncollectedWarningsSubunit.test_starting_with_and_exclude |
344 | +breezy.tests.test_selftest.TestUncollectedWarningsSubunit.test_testsuite |
345 | breezy.tests.test_selftest.TestUncollectedWarnings.test_additonal_decorator |
346 | breezy.tests.test_selftest.TestUncollectedWarnings.test_exclude_pattern |
347 | breezy.tests.test_selftest.TestUncollectedWarnings.test_matching_tests_first |
There's some ugliness added here, but you do also remove a compat check of mine from 2011 so probably even enough for now. :)