From 729967637c1ead8042bca8e1ece3906f6f6ed6e7 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 10 Jan 2011 17:15:55 -0600 Subject: Tolerate streams with the \r missing from the chunk length. --- python/subunit/tests/test_chunked.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_chunked.py b/python/subunit/tests/test_chunked.py index a24e31e..681af6b 100644 --- a/python/subunit/tests/test_chunked.py +++ b/python/subunit/tests/test_chunked.py @@ -1,6 +1,7 @@ # # subunit: extensions to python unittest to get test results from subprocesses. # Copyright (C) 2005 Robert Collins +# Copyright (C) 2011 Martin Pool # # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause # license at the users choice. A copy of both licenses are available in the @@ -86,6 +87,13 @@ class TestDecode(unittest.TestCase): self.assertEqual('', self.decoder.write('0\r\n')) self.assertEqual('1' * 65536 + '2' * 65536, self.output.getvalue()) + def test_decode_newline(self): + """Tolerate chunk markers with no cr character.""" + self.assertEqual(None, self.decoder.write('a\n')) + self.assertEqual(None, self.decoder.write('abcdeabcde')) + self.assertEqual(None, self.decoder.write('0\n')) + self.assertEqual('abcdeabcde', self.output.getvalue()) + class TestEncode(unittest.TestCase): -- cgit v1.2.1 From 0de847bb324e3bf3345c355f899c939180ecb406 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Tue, 11 Jan 2011 22:49:26 -0600 Subject: Default to (more) strict decoding of chunked parts --- python/subunit/tests/test_chunked.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_chunked.py b/python/subunit/tests/test_chunked.py index 681af6b..4fb99bf 100644 --- a/python/subunit/tests/test_chunked.py +++ b/python/subunit/tests/test_chunked.py @@ -87,13 +87,29 @@ class TestDecode(unittest.TestCase): self.assertEqual('', self.decoder.write('0\r\n')) self.assertEqual('1' * 65536 + '2' * 65536, self.output.getvalue()) - def test_decode_newline(self): + def test_decode_newline_nonstrict(self): """Tolerate chunk markers with no cr character.""" + # From + self.decoder = subunit.chunked.Decoder(self.output, strict=False) self.assertEqual(None, self.decoder.write('a\n')) self.assertEqual(None, self.decoder.write('abcdeabcde')) - self.assertEqual(None, self.decoder.write('0\n')) + self.assertEqual('', self.decoder.write('0\n')) self.assertEqual('abcdeabcde', self.output.getvalue()) + def test_decode_strict_newline_only(self): + """Reject chunk markers with no cr character in strict mode.""" + # From + self.assertRaises(ValueError, + self.decoder.write, 'a\n') + + def test_decode_strict_multiple_crs(self): + self.assertRaises(ValueError, + self.decoder.write, 'a\r\r\n') + + def test_decode_short_header(self): + self.assertRaises(ValueError, + self.decoder.write, '\n') + class TestEncode(unittest.TestCase): -- cgit v1.2.1 From 4720c35d1bfd2af2f27ceddfd039c54553ce2deb Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Fri, 28 Jan 2011 17:36:39 +0000 Subject: CR, not cr. Flakes. Whitespace. --- python/subunit/tests/test_chunked.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_chunked.py b/python/subunit/tests/test_chunked.py index 4fb99bf..eee7fe9 100644 --- a/python/subunit/tests/test_chunked.py +++ b/python/subunit/tests/test_chunked.py @@ -88,7 +88,7 @@ class TestDecode(unittest.TestCase): self.assertEqual('1' * 65536 + '2' * 65536, self.output.getvalue()) def test_decode_newline_nonstrict(self): - """Tolerate chunk markers with no cr character.""" + """Tolerate chunk markers with no CR character.""" # From self.decoder = subunit.chunked.Decoder(self.output, strict=False) self.assertEqual(None, self.decoder.write('a\n')) @@ -97,7 +97,7 @@ class TestDecode(unittest.TestCase): self.assertEqual('abcdeabcde', self.output.getvalue()) def test_decode_strict_newline_only(self): - """Reject chunk markers with no cr character in strict mode.""" + """Reject chunk markers with no CR character in strict mode.""" # From self.assertRaises(ValueError, self.decoder.write, 'a\n') -- cgit v1.2.1 From 5ab0d77e721455ba1b1be5d962becbe404769a31 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Thu, 10 Feb 2011 17:39:46 +0000 Subject: Flakes --- python/subunit/tests/test_test_protocol.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index e1287b6..ca56c8f 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -6,7 +6,7 @@ # license at the users choice. A copy of both licenses are available in the # project source as Apache-2.0 and BSD. You may not use this file except in # compliance with one of these two licences. -# +# # Unless required by applicable law or agreed to in writing, software # distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -18,7 +18,6 @@ import datetime import unittest from StringIO import StringIO import os -import sys from testtools.content import Content, TracebackContent from testtools.content_type import ContentType @@ -61,7 +60,6 @@ class TestProtocolServerForward(unittest.TestCase): pipe = StringIO("test old mcdonald\n" "success old mcdonald\n") protocol.readFrom(pipe) - mcdonald = subunit.RemotedTestCase("old mcdonald") self.assertEqual(client.testsRun, 1) self.assertEqual(pipe.getvalue(), out.getvalue()) @@ -74,7 +72,7 @@ class TestProtocolServerForward(unittest.TestCase): protocol.readFrom(pipe) self.assertEqual(client.testsRun, 0) self.assertEqual("", out.getvalue()) - + class TestTestProtocolServerPipe(unittest.TestCase): @@ -90,7 +88,6 @@ class TestTestProtocolServerPipe(unittest.TestCase): "test an error\n" "error an error\n") protocol.readFrom(pipe) - mcdonald = subunit.RemotedTestCase("old mcdonald") bing = subunit.RemotedTestCase("bing crosby") an_error = subunit.RemotedTestCase("an error") self.assertEqual(client.errors, @@ -311,7 +308,7 @@ class TestTestProtocolServerLostConnection(unittest.TestCase): self.protocol.lineReceived("%s old mcdonald %s" % (outcome, opening)) self.protocol.lostConnection() failure = subunit.RemoteError( - u"lost connection during %s report of test 'old mcdonald'" % + u"lost connection during %s report of test 'old mcdonald'" % outcome) self.assertEqual([ ('startTest', self.test), @@ -686,10 +683,10 @@ class TestTestProtocolServerAddSuccess(unittest.TestCase): def test_simple_success_colon(self): self.simple_success_keyword("failure:") - def test_simple_success(self): + def test_simple_failure(self): self.simple_success_keyword("successful") - def test_simple_success_colon(self): + def test_simple_failure_colon(self): self.simple_success_keyword("successful:") def assertSuccess(self, details): @@ -946,7 +943,7 @@ class TestIsolatedTestCase(unittest.TestCase): def test_construct(self): - test = self.SampleIsolatedTestCase("test_sets_global_state") + self.SampleIsolatedTestCase("test_sets_global_state") def test_run(self): result = unittest.TestResult() @@ -982,7 +979,7 @@ class TestIsolatedTestSuite(unittest.TestCase): def test_construct(self): - suite = subunit.IsolatedTestSuite() + subunit.IsolatedTestSuite() def test_run(self): result = unittest.TestResult() @@ -1117,7 +1114,7 @@ class TestTestProtocolClient(unittest.TestCase): self.assertEqual( self.io.getvalue(), 'skip: %s [\nHas it really?\n]\n' % self.test.id()) - + def test_add_skip_details(self): """Test addSkip on a TestProtocolClient with details.""" details = {'reason':Content( -- cgit v1.2.1 From 5358e383f7bdea693ec5f0e6182d8a45df9e8c3b Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Thu, 10 Feb 2011 17:42:15 +0000 Subject: More flakes to fix up --- python/subunit/tests/test_test_protocol.py | 8 +------- python/subunit/tests/test_test_results.py | 20 +++++++------------- 2 files changed, 8 insertions(+), 20 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index ca56c8f..f7bab5c 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -678,15 +678,9 @@ class TestTestProtocolServerAddSuccess(unittest.TestCase): ], self.client._events) def test_simple_success(self): - self.simple_success_keyword("failure") - - def test_simple_success_colon(self): - self.simple_success_keyword("failure:") - - def test_simple_failure(self): self.simple_success_keyword("successful") - def test_simple_failure_colon(self): + def test_simple_success_colon(self): self.simple_success_keyword("successful:") def assertSuccess(self, details): diff --git a/python/subunit/tests/test_test_results.py b/python/subunit/tests/test_test_results.py index fe82c04..a2dad96 100644 --- a/python/subunit/tests/test_test_results.py +++ b/python/subunit/tests/test_test_results.py @@ -6,7 +6,7 @@ # license at the users choice. A copy of both licenses are available in the # project source as Apache-2.0 and BSD. You may not use this file except in # compliance with one of these two licences. -# +# # Unless required by applicable law or agreed to in writing, software # distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -16,12 +16,6 @@ import datetime import unittest -from StringIO import StringIO -import os -import sys - -from testtools.content_type import ContentType -from testtools.content import Content import subunit import subunit.iso8601 as iso8601 @@ -82,22 +76,22 @@ class TestHookedTestResultDecorator(unittest.TestCase): def test_startTest(self): self.result.startTest(self) - + def test_startTestRun(self): self.result.startTestRun() - + def test_stopTest(self): self.result.stopTest(self) - + def test_stopTestRun(self): self.result.stopTestRun() def test_addError(self): self.result.addError(self, subunit.RemoteError()) - + def test_addError_details(self): self.result.addError(self, details={}) - + def test_addFailure(self): self.result.addFailure(self, subunit.RemoteError()) @@ -142,7 +136,7 @@ class TestHookedTestResultDecorator(unittest.TestCase): def test_time(self): self.result.time(None) - + class TestAutoTimingTestResultDecorator(unittest.TestCase): -- cgit v1.2.1 From d9936a42c5204813c56ac9dd361e4ce6545cbea0 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Thu, 10 Feb 2011 17:44:07 +0000 Subject: More flakes. --- python/subunit/tests/test_subunit_filter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py index 3c65ed3..91f6f1f 100644 --- a/python/subunit/tests/test_subunit_filter.py +++ b/python/subunit/tests/test_subunit_filter.py @@ -6,7 +6,7 @@ # license at the users choice. A copy of both licenses are available in the # project source as Apache-2.0 and BSD. You may not use this file except in # compliance with one of these two licences. -# +# # Unless required by applicable law or agreed to in writing, software # distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -76,7 +76,7 @@ class TestTestResultFilter(unittest.TestCase): self.assertEqual(3, self.filtered_result.testsRun) def test_include_success(self): - """Success's can be included if requested.""" + """Successes can be included if requested.""" self.filtered_result = unittest.TestResult() self.filter = TestResultFilter(self.filtered_result, filter_success=False) @@ -128,7 +128,7 @@ test todo xfail todo """) self.input_stream.seek(0) - + def test_suite(): loader = subunit.tests.TestUtil.TestLoader() -- cgit v1.2.1 From 273427a2f62b46c6e9e89ba5837a96684929c63c Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Thu, 10 Feb 2011 17:46:01 +0000 Subject: Return, rather than setting an attribute --- python/subunit/tests/test_subunit_filter.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py index 91f6f1f..34283a2 100644 --- a/python/subunit/tests/test_subunit_filter.py +++ b/python/subunit/tests/test_subunit_filter.py @@ -101,18 +101,18 @@ class TestTestResultFilter(unittest.TestCase): self.assertEqual(1, self.filtered_result.testsRun) def run_tests(self): - self.setUpTestStream() - self.test = subunit.ProtocolTestCase(self.input_stream) + input_stream = self.getTestStream() + self.test = subunit.ProtocolTestCase(input_stream) self.test.run(self.filter) - def setUpTestStream(self): + def getTestStream(self): # While TestResultFilter works on python objects, using a subunit # stream is an easy pithy way of getting a series of test objects to # call into the TestResult, and as TestResultFilter is intended for # use with subunit also has the benefit of detecting any interface # skew issues. - self.input_stream = StringIO() - self.input_stream.write("""tags: global + input_stream = StringIO() + input_stream.write("""tags: global test passed success passed test failed @@ -127,7 +127,8 @@ skip skipped test todo xfail todo """) - self.input_stream.seek(0) + input_stream.seek(0) + return input_stream def test_suite(): -- cgit v1.2.1 From 607649aa4499c299a9da9daa6c12b0d4f63c60ff Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Thu, 10 Feb 2011 17:57:52 +0000 Subject: Pass the filter in. --- python/subunit/tests/test_subunit_filter.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py index 34283a2..52e9f91 100644 --- a/python/subunit/tests/test_subunit_filter.py +++ b/python/subunit/tests/test_subunit_filter.py @@ -32,8 +32,8 @@ class TestTestResultFilter(unittest.TestCase): def test_default(self): """The default is to exclude success and include everything else.""" self.filtered_result = unittest.TestResult() - self.filter = TestResultFilter(self.filtered_result) - self.run_tests() + result_filter = TestResultFilter(self.filtered_result) + self.run_tests(result_filter) # skips are seen as success by default python TestResult. self.assertEqual(['error'], [error[0].id() for error in self.filtered_result.errors]) @@ -44,9 +44,9 @@ class TestTestResultFilter(unittest.TestCase): def test_exclude_errors(self): self.filtered_result = unittest.TestResult() - self.filter = TestResultFilter(self.filtered_result, + result_filter = TestResultFilter(self.filtered_result, filter_error=True) - self.run_tests() + self.run_tests(result_filter) # skips are seen as errors by default python TestResult. self.assertEqual([], self.filtered_result.errors) self.assertEqual(['failed'], @@ -56,9 +56,9 @@ class TestTestResultFilter(unittest.TestCase): def test_exclude_failure(self): self.filtered_result = unittest.TestResult() - self.filter = TestResultFilter(self.filtered_result, + result_filter = TestResultFilter(self.filtered_result, filter_failure=True) - self.run_tests() + self.run_tests(result_filter) self.assertEqual(['error'], [error[0].id() for error in self.filtered_result.errors]) self.assertEqual([], @@ -68,9 +68,9 @@ class TestTestResultFilter(unittest.TestCase): def test_exclude_skips(self): self.filtered_result = subunit.TestResultStats(None) - self.filter = TestResultFilter(self.filtered_result, + result_filter = TestResultFilter(self.filtered_result, filter_skip=True) - self.run_tests() + self.run_tests(result_filter) self.assertEqual(0, self.filtered_result.skipped_tests) self.assertEqual(2, self.filtered_result.failed_tests) self.assertEqual(3, self.filtered_result.testsRun) @@ -78,9 +78,9 @@ class TestTestResultFilter(unittest.TestCase): def test_include_success(self): """Successes can be included if requested.""" self.filtered_result = unittest.TestResult() - self.filter = TestResultFilter(self.filtered_result, + result_filter = TestResultFilter(self.filtered_result, filter_success=False) - self.run_tests() + self.run_tests(result_filter) self.assertEqual(['error'], [error[0].id() for error in self.filtered_result.errors]) self.assertEqual(['failed'], @@ -93,17 +93,17 @@ class TestTestResultFilter(unittest.TestCase): self.filtered_result = unittest.TestResult() def filter_cb(test, outcome, err, details): return outcome == 'success' - self.filter = TestResultFilter(self.filtered_result, + result_filter = TestResultFilter(self.filtered_result, filter_predicate=filter_cb, filter_success=False) - self.run_tests() + self.run_tests(result_filter) # Only success should pass self.assertEqual(1, self.filtered_result.testsRun) - def run_tests(self): + def run_tests(self, result_filter): input_stream = self.getTestStream() self.test = subunit.ProtocolTestCase(input_stream) - self.test.run(self.filter) + self.test.run(result_filter) def getTestStream(self): # While TestResultFilter works on python objects, using a subunit -- cgit v1.2.1 From 273f9cb733fe18c7dd315d1c1d9c846514b6e5fa Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Thu, 10 Feb 2011 17:58:09 +0000 Subject: Delete unused method. --- python/subunit/tests/test_subunit_filter.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py index 52e9f91..448f06c 100644 --- a/python/subunit/tests/test_subunit_filter.py +++ b/python/subunit/tests/test_subunit_filter.py @@ -26,9 +26,6 @@ from subunit.test_results import TestResultFilter class TestTestResultFilter(unittest.TestCase): """Test for TestResultFilter, a TestResult object which filters tests.""" - def _setUp(self): - self.output = StringIO() - def test_default(self): """The default is to exclude success and include everything else.""" self.filtered_result = unittest.TestResult() -- cgit v1.2.1 From fce3670662a65c9cb3232c2a172e95aadc651bbb Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Thu, 10 Feb 2011 17:58:49 +0000 Subject: No need to store on the object either. --- python/subunit/tests/test_subunit_filter.py | 56 ++++++++++++++--------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py index 448f06c..348f4bd 100644 --- a/python/subunit/tests/test_subunit_filter.py +++ b/python/subunit/tests/test_subunit_filter.py @@ -28,74 +28,74 @@ class TestTestResultFilter(unittest.TestCase): def test_default(self): """The default is to exclude success and include everything else.""" - self.filtered_result = unittest.TestResult() - result_filter = TestResultFilter(self.filtered_result) + filtered_result = unittest.TestResult() + result_filter = TestResultFilter(filtered_result) self.run_tests(result_filter) # skips are seen as success by default python TestResult. self.assertEqual(['error'], - [error[0].id() for error in self.filtered_result.errors]) + [error[0].id() for error in filtered_result.errors]) self.assertEqual(['failed'], [failure[0].id() for failure in - self.filtered_result.failures]) - self.assertEqual(4, self.filtered_result.testsRun) + filtered_result.failures]) + self.assertEqual(4, filtered_result.testsRun) def test_exclude_errors(self): - self.filtered_result = unittest.TestResult() - result_filter = TestResultFilter(self.filtered_result, + filtered_result = unittest.TestResult() + result_filter = TestResultFilter(filtered_result, filter_error=True) self.run_tests(result_filter) # skips are seen as errors by default python TestResult. - self.assertEqual([], self.filtered_result.errors) + self.assertEqual([], filtered_result.errors) self.assertEqual(['failed'], [failure[0].id() for failure in - self.filtered_result.failures]) - self.assertEqual(3, self.filtered_result.testsRun) + filtered_result.failures]) + self.assertEqual(3, filtered_result.testsRun) def test_exclude_failure(self): - self.filtered_result = unittest.TestResult() - result_filter = TestResultFilter(self.filtered_result, + filtered_result = unittest.TestResult() + result_filter = TestResultFilter(filtered_result, filter_failure=True) self.run_tests(result_filter) self.assertEqual(['error'], - [error[0].id() for error in self.filtered_result.errors]) + [error[0].id() for error in filtered_result.errors]) self.assertEqual([], [failure[0].id() for failure in - self.filtered_result.failures]) - self.assertEqual(3, self.filtered_result.testsRun) + filtered_result.failures]) + self.assertEqual(3, filtered_result.testsRun) def test_exclude_skips(self): - self.filtered_result = subunit.TestResultStats(None) - result_filter = TestResultFilter(self.filtered_result, + filtered_result = subunit.TestResultStats(None) + result_filter = TestResultFilter(filtered_result, filter_skip=True) self.run_tests(result_filter) - self.assertEqual(0, self.filtered_result.skipped_tests) - self.assertEqual(2, self.filtered_result.failed_tests) - self.assertEqual(3, self.filtered_result.testsRun) + self.assertEqual(0, filtered_result.skipped_tests) + self.assertEqual(2, filtered_result.failed_tests) + self.assertEqual(3, filtered_result.testsRun) def test_include_success(self): """Successes can be included if requested.""" - self.filtered_result = unittest.TestResult() - result_filter = TestResultFilter(self.filtered_result, + filtered_result = unittest.TestResult() + result_filter = TestResultFilter(filtered_result, filter_success=False) self.run_tests(result_filter) self.assertEqual(['error'], - [error[0].id() for error in self.filtered_result.errors]) + [error[0].id() for error in filtered_result.errors]) self.assertEqual(['failed'], [failure[0].id() for failure in - self.filtered_result.failures]) - self.assertEqual(5, self.filtered_result.testsRun) + filtered_result.failures]) + self.assertEqual(5, filtered_result.testsRun) def test_filter_predicate(self): """You can filter by predicate callbacks""" - self.filtered_result = unittest.TestResult() + filtered_result = unittest.TestResult() def filter_cb(test, outcome, err, details): return outcome == 'success' - result_filter = TestResultFilter(self.filtered_result, + result_filter = TestResultFilter(filtered_result, filter_predicate=filter_cb, filter_success=False) self.run_tests(result_filter) # Only success should pass - self.assertEqual(1, self.filtered_result.testsRun) + self.assertEqual(1, filtered_result.testsRun) def run_tests(self, result_filter): input_stream = self.getTestStream() -- cgit v1.2.1 From cfed1cc123546138685e177b2832b922576fb83c Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Thu, 10 Feb 2011 17:59:10 +0000 Subject: No need for that either --- python/subunit/tests/test_subunit_filter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py index 348f4bd..9c9e165 100644 --- a/python/subunit/tests/test_subunit_filter.py +++ b/python/subunit/tests/test_subunit_filter.py @@ -99,8 +99,8 @@ class TestTestResultFilter(unittest.TestCase): def run_tests(self, result_filter): input_stream = self.getTestStream() - self.test = subunit.ProtocolTestCase(input_stream) - self.test.run(result_filter) + test = subunit.ProtocolTestCase(input_stream) + test.run(result_filter) def getTestStream(self): # While TestResultFilter works on python objects, using a subunit -- cgit v1.2.1 From 14c50a345f9867424d69531822b0e8dd420742d2 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Fri, 11 Feb 2011 16:19:01 +0000 Subject: Formatting. --- python/subunit/tests/test_subunit_filter.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py index 9c9e165..ac46f15 100644 --- a/python/subunit/tests/test_subunit_filter.py +++ b/python/subunit/tests/test_subunit_filter.py @@ -41,8 +41,7 @@ class TestTestResultFilter(unittest.TestCase): def test_exclude_errors(self): filtered_result = unittest.TestResult() - result_filter = TestResultFilter(filtered_result, - filter_error=True) + result_filter = TestResultFilter(filtered_result, filter_error=True) self.run_tests(result_filter) # skips are seen as errors by default python TestResult. self.assertEqual([], filtered_result.errors) @@ -53,8 +52,7 @@ class TestTestResultFilter(unittest.TestCase): def test_exclude_failure(self): filtered_result = unittest.TestResult() - result_filter = TestResultFilter(filtered_result, - filter_failure=True) + result_filter = TestResultFilter(filtered_result, filter_failure=True) self.run_tests(result_filter) self.assertEqual(['error'], [error[0].id() for error in filtered_result.errors]) @@ -65,8 +63,7 @@ class TestTestResultFilter(unittest.TestCase): def test_exclude_skips(self): filtered_result = subunit.TestResultStats(None) - result_filter = TestResultFilter(filtered_result, - filter_skip=True) + result_filter = TestResultFilter(filtered_result, filter_skip=True) self.run_tests(result_filter) self.assertEqual(0, filtered_result.skipped_tests) self.assertEqual(2, filtered_result.failed_tests) -- cgit v1.2.1 From 8313ffeb9ad36af77d29724e29b1801d80f8df7c Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Fri, 11 Feb 2011 16:22:21 +0000 Subject: Try to make the test set up a little more data driven. --- python/subunit/tests/test_subunit_filter.py | 52 ++++++++++++++--------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py index ac46f15..2f26f39 100644 --- a/python/subunit/tests/test_subunit_filter.py +++ b/python/subunit/tests/test_subunit_filter.py @@ -23,9 +23,34 @@ import subunit from subunit.test_results import TestResultFilter +def make_stream(bytes): + """Take a string and return a stream from which that string can be read.""" + stream = StringIO() + stream.write(bytes) + stream.seek(0) + return stream + + class TestTestResultFilter(unittest.TestCase): """Test for TestResultFilter, a TestResult object which filters tests.""" + example_subunit_stream = """\ +tags: global +test passed +success passed +test failed +tags: local +failure failed +test error +error error [ +error details +] +test skipped +skip skipped +test todo +xfail todo +""" + def test_default(self): """The default is to exclude success and include everything else.""" filtered_result = unittest.TestResult() @@ -95,35 +120,10 @@ class TestTestResultFilter(unittest.TestCase): self.assertEqual(1, filtered_result.testsRun) def run_tests(self, result_filter): - input_stream = self.getTestStream() + input_stream = make_stream(self.example_subunit_stream) test = subunit.ProtocolTestCase(input_stream) test.run(result_filter) - def getTestStream(self): - # While TestResultFilter works on python objects, using a subunit - # stream is an easy pithy way of getting a series of test objects to - # call into the TestResult, and as TestResultFilter is intended for - # use with subunit also has the benefit of detecting any interface - # skew issues. - input_stream = StringIO() - input_stream.write("""tags: global -test passed -success passed -test failed -tags: local -failure failed -test error -error error [ -error details -] -test skipped -skip skipped -test todo -xfail todo -""") - input_stream.seek(0) - return input_stream - def test_suite(): loader = subunit.tests.TestUtil.TestLoader() -- cgit v1.2.1 From b32d51316660c0923eb132f0e3aaadd5b269bea9 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Fri, 11 Feb 2011 16:23:19 +0000 Subject: Parametrize the subunit input. --- python/subunit/tests/test_subunit_filter.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py index 2f26f39..69e32a0 100644 --- a/python/subunit/tests/test_subunit_filter.py +++ b/python/subunit/tests/test_subunit_filter.py @@ -119,9 +119,10 @@ xfail todo # Only success should pass self.assertEqual(1, filtered_result.testsRun) - def run_tests(self, result_filter): - input_stream = make_stream(self.example_subunit_stream) - test = subunit.ProtocolTestCase(input_stream) + def run_tests(self, result_filter, input_stream=None): + if input_stream is None: + input_stream = self.example_subunit_stream + test = subunit.ProtocolTestCase(make_stream(input_stream)) test.run(result_filter) -- cgit v1.2.1 From a079bfb4c2a37a7d12b0f2cff51f079bf81c889f Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Fri, 11 Feb 2011 16:25:36 +0000 Subject: Clarity --- python/subunit/tests/test_subunit_filter.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py index 69e32a0..89f5212 100644 --- a/python/subunit/tests/test_subunit_filter.py +++ b/python/subunit/tests/test_subunit_filter.py @@ -34,6 +34,10 @@ def make_stream(bytes): class TestTestResultFilter(unittest.TestCase): """Test for TestResultFilter, a TestResult object which filters tests.""" + # While TestResultFilter works on python objects, using a subunit stream + # is an easy pithy way of getting a series of test objects to call into + # the TestResult, and as TestResultFilter is intended for use with subunit + # also has the benefit of detecting any interface skew issues. example_subunit_stream = """\ tags: global test passed @@ -51,6 +55,18 @@ test todo xfail todo """ + def run_tests(self, result_filter, input_stream=None): + """Run tests through the given filter. + + :param result_filter: A filtering TestResult object. + :param input_stream: Bytes of subunit stream data. If not provided, + uses TestTestResultFilter.example_subunit_stream. + """ + if input_stream is None: + input_stream = self.example_subunit_stream + test = subunit.ProtocolTestCase(make_stream(input_stream)) + test.run(result_filter) + def test_default(self): """The default is to exclude success and include everything else.""" filtered_result = unittest.TestResult() @@ -119,12 +135,6 @@ xfail todo # Only success should pass self.assertEqual(1, filtered_result.testsRun) - def run_tests(self, result_filter, input_stream=None): - if input_stream is None: - input_stream = self.example_subunit_stream - test = subunit.ProtocolTestCase(make_stream(input_stream)) - test.run(result_filter) - def test_suite(): loader = subunit.tests.TestUtil.TestLoader() -- cgit v1.2.1 From 6d6297fef98e8e86cdea243922cc2e79d5c4641f Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Fri, 11 Feb 2011 16:45:49 +0000 Subject: Failing test that demonstrates the bug. --- python/subunit/tests/test_subunit_filter.py | 30 ++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py index 89f5212..786ef46 100644 --- a/python/subunit/tests/test_subunit_filter.py +++ b/python/subunit/tests/test_subunit_filter.py @@ -16,9 +16,14 @@ """Tests for subunit.TestResultFilter.""" +from datetime import datetime +from subunit import iso8601 import unittest from StringIO import StringIO +from testtools import TestCase +from testtools.testresult.doubles import ExtendedTestResult + import subunit from subunit.test_results import TestResultFilter @@ -31,7 +36,7 @@ def make_stream(bytes): return stream -class TestTestResultFilter(unittest.TestCase): +class TestTestResultFilter(TestCase): """Test for TestResultFilter, a TestResult object which filters tests.""" # While TestResultFilter works on python objects, using a subunit stream @@ -135,6 +140,29 @@ xfail todo # Only success should pass self.assertEqual(1, filtered_result.testsRun) + def test_time_ordering_preserved(self): + # Passing a subunit stream through TestResultFilter preserves the + # relative ordering of 'time' directives and any other subunit + # directives that are still included. + dates = [ + datetime(year=2000, month=1, day=i, tzinfo=iso8601.Utc()) + for i in range(1, 4)] + subunit_stream = '\n'.join([ + "time: %s", + "test: foo", + "time: %s", + "error: foo", + "time: %s"]) % tuple(dates) + result = ExtendedTestResult() + result_filter = TestResultFilter(result) + self.run_tests(result_filter, subunit_stream) + self.assertEquals( + [('time', dates[0]), + ('startTest', 'foo'), + ('time', dates[1]), + ('addError', 'foo'), + ('time', dates[2])], result._events) + def test_suite(): loader = subunit.tests.TestUtil.TestLoader() -- cgit v1.2.1 From dd089db28901fa5c05dc5ead9a6db1ca9ef5e80b Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Fri, 11 Feb 2011 17:43:01 +0000 Subject: Fix the immediate bug. --- python/subunit/tests/test_subunit_filter.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py index 786ef46..0548966 100644 --- a/python/subunit/tests/test_subunit_filter.py +++ b/python/subunit/tests/test_subunit_filter.py @@ -144,24 +144,24 @@ xfail todo # Passing a subunit stream through TestResultFilter preserves the # relative ordering of 'time' directives and any other subunit # directives that are still included. - dates = [ - datetime(year=2000, month=1, day=i, tzinfo=iso8601.Utc()) - for i in range(1, 4)] + date_a = datetime(year=2000, month=1, day=1, tzinfo=iso8601.UTC) + date_b = datetime(year=2000, month=1, day=2, tzinfo=iso8601.UTC) subunit_stream = '\n'.join([ "time: %s", "test: foo", "time: %s", "error: foo", - "time: %s"]) % tuple(dates) + ""]) % (date_a, date_b) result = ExtendedTestResult() result_filter = TestResultFilter(result) self.run_tests(result_filter, subunit_stream) + foo = subunit.RemotedTestCase('foo') self.assertEquals( - [('time', dates[0]), - ('startTest', 'foo'), - ('time', dates[1]), - ('addError', 'foo'), - ('time', dates[2])], result._events) + [('time', date_a), + ('startTest', foo), + ('time', date_b), + ('addError', foo, {}), + ('stopTest', foo)], result._events) def test_suite(): -- cgit v1.2.1 From 77c9c58133de6bee368c524918c0fa8978d254da Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Fri, 11 Feb 2011 17:45:41 +0000 Subject: Pass through time when we aren't in tests. --- python/subunit/tests/test_subunit_filter.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py index 0548966..a728860 100644 --- a/python/subunit/tests/test_subunit_filter.py +++ b/python/subunit/tests/test_subunit_filter.py @@ -146,12 +146,14 @@ xfail todo # directives that are still included. date_a = datetime(year=2000, month=1, day=1, tzinfo=iso8601.UTC) date_b = datetime(year=2000, month=1, day=2, tzinfo=iso8601.UTC) + date_c = datetime(year=2000, month=1, day=3, tzinfo=iso8601.UTC) subunit_stream = '\n'.join([ "time: %s", "test: foo", "time: %s", "error: foo", - ""]) % (date_a, date_b) + "time: %s", + ""]) % (date_a, date_b, date_c) result = ExtendedTestResult() result_filter = TestResultFilter(result) self.run_tests(result_filter, subunit_stream) @@ -161,7 +163,8 @@ xfail todo ('startTest', foo), ('time', date_b), ('addError', foo, {}), - ('stopTest', foo)], result._events) + ('stopTest', foo), + ('time', date_c)], result._events) def test_suite(): -- cgit v1.2.1 From c592e36438ec3931c1a8f0e324e382f005eaa31f Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Sat, 12 Feb 2011 11:10:13 +0000 Subject: Delete unnecessary code. --- python/subunit/tests/test_subunit_filter.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py index a728860..cf6c2b6 100644 --- a/python/subunit/tests/test_subunit_filter.py +++ b/python/subunit/tests/test_subunit_filter.py @@ -28,14 +28,6 @@ import subunit from subunit.test_results import TestResultFilter -def make_stream(bytes): - """Take a string and return a stream from which that string can be read.""" - stream = StringIO() - stream.write(bytes) - stream.seek(0) - return stream - - class TestTestResultFilter(TestCase): """Test for TestResultFilter, a TestResult object which filters tests.""" @@ -69,7 +61,7 @@ xfail todo """ if input_stream is None: input_stream = self.example_subunit_stream - test = subunit.ProtocolTestCase(make_stream(input_stream)) + test = subunit.ProtocolTestCase(StringIO(input_stream)) test.run(result_filter) def test_default(self): -- cgit v1.2.1 From 255d00653139619a8d1eb6a0efaefbbc842e5bbb Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Sat, 12 Feb 2011 12:10:06 +0000 Subject: Get started, fix a bug in subunit's decorator. --- python/subunit/tests/test_test_results.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_test_results.py b/python/subunit/tests/test_test_results.py index a2dad96..0bc7e24 100644 --- a/python/subunit/tests/test_test_results.py +++ b/python/subunit/tests/test_test_results.py @@ -17,6 +17,9 @@ import datetime import unittest +from testtools import TestCase +from testtools.testresult.doubles import ExtendedTestResult + import subunit import subunit.iso8601 as iso8601 import subunit.test_results @@ -187,6 +190,16 @@ class TestAutoTimingTestResultDecorator(unittest.TestCase): self.assertNotEqual(None, self.decorated._calls[2]) +class TestTagCollapsingDecorator(TestCase): + + def test_tags_forwarded_outside_of_tests(self): + result = ExtendedTestResult() + tag_collapser = subunit.test_results.TagCollapsingDecorator(result) + tag_collapser.tags(set(['a', 'b']), set()) + self.assertEquals( + [('tags', set(['a', 'b']), set([]))], result._events) + + def test_suite(): loader = subunit.tests.TestUtil.TestLoader() result = loader.loadTestsFromName(__name__) -- cgit v1.2.1 From 0f644eda8f3af105622ef30c7c6739c6b26fe7e8 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Sat, 12 Feb 2011 12:16:36 +0000 Subject: Implement the tag collapsing logic by stealing stuff from TRF and fixing it. --- python/subunit/tests/test_test_results.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_test_results.py b/python/subunit/tests/test_test_results.py index 0bc7e24..7aed8a4 100644 --- a/python/subunit/tests/test_test_results.py +++ b/python/subunit/tests/test_test_results.py @@ -199,6 +199,21 @@ class TestTagCollapsingDecorator(TestCase): self.assertEquals( [('tags', set(['a', 'b']), set([]))], result._events) + def test_tags_collapsed_inside_of_tests(self): + result = ExtendedTestResult() + tag_collapser = subunit.test_results.TagCollapsingDecorator(result) + test = subunit.RemotedTestCase('foo') + tag_collapser.startTest(test) + tag_collapser.tags(set(['a']), set()) + tag_collapser.tags(set(['b']), set(['a'])) + tag_collapser.tags(set(['c']), set()) + tag_collapser.stopTest(test) + self.assertEquals( + [('startTest', test), + ('tags', set(['b', 'c']), set(['a'])), + ('stopTest', test)], + result._events) + def test_suite(): loader = subunit.tests.TestUtil.TestLoader() -- cgit v1.2.1 From 7fd32930b2d9bff0c4f8f823a313c03beedce451 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Sun, 13 Feb 2011 14:39:43 +0000 Subject: Add a time collapsing decorator. --- python/subunit/tests/test_test_results.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_test_results.py b/python/subunit/tests/test_test_results.py index 7aed8a4..8535d56 100644 --- a/python/subunit/tests/test_test_results.py +++ b/python/subunit/tests/test_test_results.py @@ -215,6 +215,31 @@ class TestTagCollapsingDecorator(TestCase): result._events) +class TestTimeCollapsingDecorator(TestCase): + + def make_time(self): + # Heh heh. + return datetime.datetime( + 2000, 1, self.getUniqueInteger(), tzinfo=iso8601.UTC) + + def test_initial_time_forwarded(self): + result = ExtendedTestResult() + tag_collapser = subunit.test_results.TimeCollapsingDecorator(result) + a_time = self.make_time() + tag_collapser.time(a_time) + self.assertEquals([('time', a_time)], result._events) + + def test_time_collapsed(self): + result = ExtendedTestResult() + tag_collapser = subunit.test_results.TimeCollapsingDecorator(result) + times = [self.make_time() for i in range(5)] + for a_time in times: + tag_collapser.time(a_time) + tag_collapser.startTest(subunit.RemotedTestCase('foo')) + self.assertEquals( + [('time', times[0]), ('time', times[-1])], result._events[:-1]) + + def test_suite(): loader = subunit.tests.TestUtil.TestLoader() result = loader.loadTestsFromName(__name__) -- cgit v1.2.1 From d86c97154604bd029774d8095b394de26af4867c Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Sun, 13 Feb 2011 14:48:21 +0000 Subject: Properly handle multiple events. --- python/subunit/tests/test_test_results.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_test_results.py b/python/subunit/tests/test_test_results.py index 8535d56..8633b44 100644 --- a/python/subunit/tests/test_test_results.py +++ b/python/subunit/tests/test_test_results.py @@ -223,13 +223,16 @@ class TestTimeCollapsingDecorator(TestCase): 2000, 1, self.getUniqueInteger(), tzinfo=iso8601.UTC) def test_initial_time_forwarded(self): + # We always forward the first time event we see. result = ExtendedTestResult() tag_collapser = subunit.test_results.TimeCollapsingDecorator(result) a_time = self.make_time() tag_collapser.time(a_time) self.assertEquals([('time', a_time)], result._events) - def test_time_collapsed(self): + def test_time_collapsed_to_first_and_last(self): + # If there are many consecutive time events, only the first and last + # are sent through. result = ExtendedTestResult() tag_collapser = subunit.test_results.TimeCollapsingDecorator(result) times = [self.make_time() for i in range(5)] @@ -239,6 +242,27 @@ class TestTimeCollapsingDecorator(TestCase): self.assertEquals( [('time', times[0]), ('time', times[-1])], result._events[:-1]) + def test_only_one_time_sent(self): + # If we receive a single time event followed by a non-time event, we + # send exactly one time event. + result = ExtendedTestResult() + tag_collapser = subunit.test_results.TimeCollapsingDecorator(result) + a_time = self.make_time() + tag_collapser.time(a_time) + tag_collapser.startTest(subunit.RemotedTestCase('foo')) + self.assertEquals([('time', a_time)], result._events[:-1]) + + def test_duplicate_times_not_sent(self): + # Many time events with the exact same time are collapsed into one + # time event. + result = ExtendedTestResult() + tag_collapser = subunit.test_results.TimeCollapsingDecorator(result) + a_time = self.make_time() + for i in range(5): + tag_collapser.time(a_time) + tag_collapser.startTest(subunit.RemotedTestCase('foo')) + self.assertEquals([('time', a_time)], result._events[:-1]) + def test_suite(): loader = subunit.tests.TestUtil.TestLoader() -- cgit v1.2.1 From e0581e6819db7c2872ced4d43e803ae7b5e7bd05 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Sun, 13 Feb 2011 14:52:42 +0000 Subject: Make sure that we don't send time if there are none to send. --- python/subunit/tests/test_test_results.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_test_results.py b/python/subunit/tests/test_test_results.py index 8633b44..bed2bd8 100644 --- a/python/subunit/tests/test_test_results.py +++ b/python/subunit/tests/test_test_results.py @@ -263,6 +263,21 @@ class TestTimeCollapsingDecorator(TestCase): tag_collapser.startTest(subunit.RemotedTestCase('foo')) self.assertEquals([('time', a_time)], result._events[:-1]) + def test_no_times_inserted(self): + result = ExtendedTestResult() + tag_collapser = subunit.test_results.TimeCollapsingDecorator(result) + a_time = self.make_time() + tag_collapser.time(a_time) + foo = subunit.RemotedTestCase('foo') + tag_collapser.startTest(foo) + tag_collapser.addSuccess(foo) + tag_collapser.stopTest(foo) + self.assertEquals( + [('time', a_time), + ('startTest', foo), + ('addSuccess', foo), + ('stopTest', foo)], result._events) + def test_suite(): loader = subunit.tests.TestUtil.TestLoader() -- cgit v1.2.1 From 6301e2918b5f2c880b5084f63201b2ee7de4be93 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Tue, 15 Feb 2011 10:52:45 +0000 Subject: Add different support. --- python/subunit/tests/test_test_results.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_test_results.py b/python/subunit/tests/test_test_results.py index bed2bd8..94d2274 100644 --- a/python/subunit/tests/test_test_results.py +++ b/python/subunit/tests/test_test_results.py @@ -214,6 +214,21 @@ class TestTagCollapsingDecorator(TestCase): ('stopTest', test)], result._events) + def test_tags_collapsed_inside_of_tests_different_ordering(self): + result = ExtendedTestResult() + tag_collapser = subunit.test_results.TagCollapsingDecorator(result) + test = subunit.RemotedTestCase('foo') + tag_collapser.startTest(test) + tag_collapser.tags(set(), set(['a'])) + tag_collapser.tags(set(['a', 'b']), set()) + tag_collapser.tags(set(['c']), set()) + tag_collapser.stopTest(test) + self.assertEquals( + [('startTest', test), + ('tags', set(['a', 'b', 'c']), set()), + ('stopTest', test)], + result._events) + class TestTimeCollapsingDecorator(TestCase): -- cgit v1.2.1 From 931ee641258b77bd440d76a0d5c1f3305010f7c4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 28 Mar 2011 15:02:55 +0200 Subject: Add test for TagCollapsingDecorator.testsRun. --- python/subunit/tests/test_test_results.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_test_results.py b/python/subunit/tests/test_test_results.py index 94d2274..23b8b5e 100644 --- a/python/subunit/tests/test_test_results.py +++ b/python/subunit/tests/test_test_results.py @@ -229,6 +229,11 @@ class TestTagCollapsingDecorator(TestCase): ('stopTest', test)], result._events) + def test_tags_collapsed_tests_run(self): + result = ExtendedTestResult() + tag_collapser = subunit.test_results.TagCollapsingDecorator(result) + tag_collapser.testsRun += 1 + class TestTimeCollapsingDecorator(TestCase): -- cgit v1.2.1 From 67a43dcef5f1511398ef32052d1220a0ef35ffcf Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 11 Apr 2011 15:32:47 +0200 Subject: Support --fixup-expected-failures argument to subunit-filter. --- python/subunit/tests/test_subunit_filter.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py index cf6c2b6..855aa1e 100644 --- a/python/subunit/tests/test_subunit_filter.py +++ b/python/subunit/tests/test_subunit_filter.py @@ -88,6 +88,18 @@ xfail todo filtered_result.failures]) self.assertEqual(3, filtered_result.testsRun) + def test_fixup_expected_failures(self): + filtered_result = unittest.TestResult() + result_filter = TestResultFilter(filtered_result, + fixup_expected_failures=set(["failed"])) + self.run_tests(result_filter) + self.assertEqual(['failed', 'todo'], + [error[0].id() for error in filtered_result.expectedFailures]) + self.assertEqual([], + [failure[0].id() for failure in + filtered_result.failures]) + self.assertEqual(4, filtered_result.testsRun) + def test_exclude_failure(self): filtered_result = unittest.TestResult() result_filter = TestResultFilter(filtered_result, filter_failure=True) -- cgit v1.2.1 From 990cf93fb02250ccbd42153fc1f6b87b867d977e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 11 Apr 2011 15:56:05 +0200 Subject: Filter errors as well. --- python/subunit/tests/test_subunit_filter.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py index 855aa1e..386c5a2 100644 --- a/python/subunit/tests/test_subunit_filter.py +++ b/python/subunit/tests/test_subunit_filter.py @@ -94,10 +94,18 @@ xfail todo fixup_expected_failures=set(["failed"])) self.run_tests(result_filter) self.assertEqual(['failed', 'todo'], - [error[0].id() for error in filtered_result.expectedFailures]) - self.assertEqual([], - [failure[0].id() for failure in - filtered_result.failures]) + [failure[0].id() for failure in filtered_result.expectedFailures]) + self.assertEqual([], filtered_result.failures) + self.assertEqual(4, filtered_result.testsRun) + + def test_fixup_expected_errors(self): + filtered_result = unittest.TestResult() + result_filter = TestResultFilter(filtered_result, + fixup_expected_failures=set(["error"])) + self.run_tests(result_filter) + self.assertEqual(['error', 'todo'], + [failure[0].id() for failure in filtered_result.expectedFailures]) + self.assertEqual([], filtered_result.errors) self.assertEqual(4, filtered_result.testsRun) def test_exclude_failure(self): -- cgit v1.2.1 From d3a4695b7a8678304001e6cf8dc68b64d2a7cde7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 11 Apr 2011 16:38:56 +0200 Subject: Mark unexpected successes, too. --- python/subunit/tests/test_subunit_filter.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py index 386c5a2..f8db05b 100644 --- a/python/subunit/tests/test_subunit_filter.py +++ b/python/subunit/tests/test_subunit_filter.py @@ -108,6 +108,15 @@ xfail todo self.assertEqual([], filtered_result.errors) self.assertEqual(4, filtered_result.testsRun) + def test_fixup_unexpected_success(self): + filtered_result = unittest.TestResult() + result_filter = TestResultFilter(filtered_result, filter_success=False, + fixup_expected_failures=set(["passed"])) + self.run_tests(result_filter) + self.assertEqual(['passed'], + [passed.id() for passed in filtered_result.unexpectedSuccesses]) + self.assertEqual(5, filtered_result.testsRun) + def test_exclude_failure(self): filtered_result = unittest.TestResult() result_filter = TestResultFilter(filtered_result, filter_failure=True) -- cgit v1.2.1 From aaa87b0d6f110bd52fe659c0fca873d820ad31f2 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Mon, 25 Apr 2011 09:40:52 +1200 Subject: Make test suite importable in py3. --- python/subunit/tests/TestUtil.py | 2 +- python/subunit/tests/test_chunked.py | 3 ++- python/subunit/tests/test_details.py | 3 ++- python/subunit/tests/test_subunit_filter.py | 2 +- python/subunit/tests/test_subunit_stats.py | 3 ++- python/subunit/tests/test_subunit_tags.py | 3 ++- python/subunit/tests/test_tap2subunit.py | 4 +++- python/subunit/tests/test_test_protocol.py | 30 ++++++++++++++--------------- 8 files changed, 28 insertions(+), 22 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/TestUtil.py b/python/subunit/tests/TestUtil.py index 1b5ba9c..39d901e 100644 --- a/python/subunit/tests/TestUtil.py +++ b/python/subunit/tests/TestUtil.py @@ -53,7 +53,7 @@ def visitTests(suite, visitor): visitor.visitSuite(test) visitTests(test, visitor) else: - print "unvisitable non-unittest.TestCase element %r (%r)" % (test, test.__class__) + print ("unvisitable non-unittest.TestCase element %r (%r)" % (test, test.__class__)) class TestSuite(unittest.TestSuite): diff --git a/python/subunit/tests/test_chunked.py b/python/subunit/tests/test_chunked.py index eee7fe9..6323b02 100644 --- a/python/subunit/tests/test_chunked.py +++ b/python/subunit/tests/test_chunked.py @@ -15,9 +15,10 @@ # limitations under that license. # -from cStringIO import StringIO import unittest +from testtools.compat import StringIO + import subunit.chunked diff --git a/python/subunit/tests/test_details.py b/python/subunit/tests/test_details.py index 41c3212..06eb430 100644 --- a/python/subunit/tests/test_details.py +++ b/python/subunit/tests/test_details.py @@ -14,9 +14,10 @@ # limitations under that license. # -from cStringIO import StringIO import unittest +from testtools.compat import StringIO + import subunit.tests from subunit import content, content_type, details diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py index cf6c2b6..682f726 100644 --- a/python/subunit/tests/test_subunit_filter.py +++ b/python/subunit/tests/test_subunit_filter.py @@ -19,9 +19,9 @@ from datetime import datetime from subunit import iso8601 import unittest -from StringIO import StringIO from testtools import TestCase +from testtools.compat import StringIO from testtools.testresult.doubles import ExtendedTestResult import subunit diff --git a/python/subunit/tests/test_subunit_stats.py b/python/subunit/tests/test_subunit_stats.py index a7f8fca..778bb7f 100644 --- a/python/subunit/tests/test_subunit_stats.py +++ b/python/subunit/tests/test_subunit_stats.py @@ -17,7 +17,8 @@ """Tests for subunit.TestResultStats.""" import unittest -from StringIO import StringIO + +from testtools.compat import StringIO import subunit diff --git a/python/subunit/tests/test_subunit_tags.py b/python/subunit/tests/test_subunit_tags.py index 227e2b7..c98506a 100644 --- a/python/subunit/tests/test_subunit_tags.py +++ b/python/subunit/tests/test_subunit_tags.py @@ -17,7 +17,8 @@ """Tests for subunit.tag_stream.""" import unittest -from StringIO import StringIO + +from testtools.compat import StringIO import subunit import subunit.test_results diff --git a/python/subunit/tests/test_tap2subunit.py b/python/subunit/tests/test_tap2subunit.py index c4ca4cd..11bc191 100644 --- a/python/subunit/tests/test_tap2subunit.py +++ b/python/subunit/tests/test_tap2subunit.py @@ -17,7 +17,9 @@ """Tests for TAP2SubUnit.""" import unittest -from StringIO import StringIO + +from testtools.compat import StringIO + import subunit diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index f7bab5c..8171696 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -16,9 +16,9 @@ import datetime import unittest -from StringIO import StringIO import os +from testtools.compat import _u, StringIO from testtools.content import Content, TracebackContent from testtools.content_type import ContentType from testtools.tests.helpers import ( @@ -286,7 +286,7 @@ class TestTestProtocolServerLostConnection(unittest.TestCase): self.protocol.lineReceived("test old mcdonald\n") self.protocol.lostConnection() failure = subunit.RemoteError( - u"lost connection during test 'old mcdonald'") + _u("lost connection during test 'old mcdonald'")) self.assertEqual([ ('startTest', self.test), ('addError', self.test, failure), @@ -299,7 +299,7 @@ class TestTestProtocolServerLostConnection(unittest.TestCase): self.protocol.lostConnection() self.assertEqual([ ('startTest', self.test), - ('addError', self.test, subunit.RemoteError(u"")), + ('addError', self.test, subunit.RemoteError(_u(""))), ('stopTest', self.test), ], self.client._events) @@ -308,7 +308,7 @@ class TestTestProtocolServerLostConnection(unittest.TestCase): self.protocol.lineReceived("%s old mcdonald %s" % (outcome, opening)) self.protocol.lostConnection() failure = subunit.RemoteError( - u"lost connection during %s report of test 'old mcdonald'" % + _u("lost connection during %s report of test 'old mcdonald'") % outcome) self.assertEqual([ ('startTest', self.test), @@ -328,7 +328,7 @@ class TestTestProtocolServerLostConnection(unittest.TestCase): self.protocol.lostConnection() self.assertEqual([ ('startTest', self.test), - ('addFailure', self.test, subunit.RemoteError(u"")), + ('addFailure', self.test, subunit.RemoteError(_u(""))), ('stopTest', self.test), ], self.client._events) @@ -542,8 +542,8 @@ class TestTestProtocolServerAddxFail(unittest.TestCase): value = details else: if error_message is not None: - value = subunit.RemoteError(u'Text attachment: traceback\n' - '------------\n' + error_message + '------------\n') + value = subunit.RemoteError(_u("Text attachment: traceback\n" + "------------\n") + error_message + _u("------------\n")) else: value = subunit.RemoteError() self.assertEqual([ @@ -841,15 +841,15 @@ class TestRemotedTestCase(unittest.TestCase): class TestRemoteError(unittest.TestCase): def test_eq(self): - error = subunit.RemoteError(u"Something went wrong") - another_error = subunit.RemoteError(u"Something went wrong") - different_error = subunit.RemoteError(u"boo!") + error = subunit.RemoteError(_u("Something went wrong")) + another_error = subunit.RemoteError(_u("Something went wrong")) + different_error = subunit.RemoteError(_u("boo!")) self.assertEqual(error, another_error) self.assertNotEqual(error, different_error) self.assertNotEqual(different_error, another_error) def test_empty_constructor(self): - self.assertEqual(subunit.RemoteError(), subunit.RemoteError(u"")) + self.assertEqual(subunit.RemoteError(), subunit.RemoteError(_u(""))) class TestExecTestCase(unittest.TestCase): @@ -1000,7 +1000,7 @@ class TestTestProtocolClient(unittest.TestCase): ContentType('text', 'plain'), lambda:['serialised\nform'])} self.sample_tb_details = dict(self.sample_details) self.sample_tb_details['traceback'] = TracebackContent( - subunit.RemoteError(u"boo qux"), self.test) + subunit.RemoteError(_u("boo qux")), self.test) def test_start_test(self): """Test startTest on a TestProtocolClient.""" @@ -1030,7 +1030,7 @@ class TestTestProtocolClient(unittest.TestCase): def test_add_failure(self): """Test addFailure on a TestProtocolClient.""" self.protocol.addFailure( - self.test, subunit.RemoteError(u"boo qux")) + self.test, subunit.RemoteError(_u("boo qux"))) self.assertEqual( self.io.getvalue(), ('failure: %s [\n' + _remote_exception_str + ': boo qux\n]\n') @@ -1054,7 +1054,7 @@ class TestTestProtocolClient(unittest.TestCase): def test_add_error(self): """Test stopTest on a TestProtocolClient.""" self.protocol.addError( - self.test, subunit.RemoteError(u"phwoar crikey")) + self.test, subunit.RemoteError(_u("phwoar crikey"))) self.assertEqual( self.io.getvalue(), ('error: %s [\n' + @@ -1079,7 +1079,7 @@ class TestTestProtocolClient(unittest.TestCase): def test_add_expected_failure(self): """Test addExpectedFailure on a TestProtocolClient.""" self.protocol.addExpectedFailure( - self.test, subunit.RemoteError(u"phwoar crikey")) + self.test, subunit.RemoteError(_u("phwoar crikey"))) self.assertEqual( self.io.getvalue(), ('xfail: %s [\n' + -- cgit v1.2.1 From 86cff2f184f6bbd34fd330bae739a29a34a78d2a Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Mon, 25 Apr 2011 11:09:54 +1200 Subject: Progress. --- python/subunit/tests/test_details.py | 28 ++++++++++++++-------------- python/subunit/tests/test_test_protocol.py | 14 +++++++------- 2 files changed, 21 insertions(+), 21 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_details.py b/python/subunit/tests/test_details.py index 06eb430..49010d2 100644 --- a/python/subunit/tests/test_details.py +++ b/python/subunit/tests/test_details.py @@ -16,7 +16,7 @@ import unittest -from testtools.compat import StringIO +from testtools.compat import _b, StringIO import subunit.tests from subunit import content, content_type, details @@ -32,20 +32,20 @@ class TestSimpleDetails(unittest.TestCase): def test_lineReceived(self): parser = details.SimpleDetailsParser(None) - parser.lineReceived("foo\n") - parser.lineReceived("bar\n") - self.assertEqual("foo\nbar\n", parser._message) + parser.lineReceived(_b("foo\n")) + parser.lineReceived(_b("bar\n")) + self.assertEqual(_b("foo\nbar\n"), parser._message) def test_lineReceived_escaped_bracket(self): parser = details.SimpleDetailsParser(None) - parser.lineReceived("foo\n") - parser.lineReceived(" ]are\n") - parser.lineReceived("bar\n") - self.assertEqual("foo\n]are\nbar\n", parser._message) + parser.lineReceived(_b("foo\n")) + parser.lineReceived(_b(" ]are\n")) + parser.lineReceived(_b("bar\n")) + self.assertEqual(_b("foo\n]are\nbar\n"), parser._message) def test_get_message(self): parser = details.SimpleDetailsParser(None) - self.assertEqual("", parser.get_message()) + self.assertEqual(_b(""), parser.get_message()) def test_get_details(self): parser = details.SimpleDetailsParser(None) @@ -54,13 +54,13 @@ class TestSimpleDetails(unittest.TestCase): expected['traceback'] = content.Content( content_type.ContentType("text", "x-traceback", {'charset': 'utf8'}), - lambda:[""]) + lambda:[_b("")]) found = parser.get_details() self.assertEqual(expected.keys(), found.keys()) self.assertEqual(expected['traceback'].content_type, found['traceback'].content_type) - self.assertEqual(''.join(expected['traceback'].iter_bytes()), - ''.join(found['traceback'].iter_bytes())) + self.assertEqual(_b('').join(expected['traceback'].iter_bytes()), + _b('').join(found['traceback'].iter_bytes())) def test_get_details_skip(self): parser = details.SimpleDetailsParser(None) @@ -68,7 +68,7 @@ class TestSimpleDetails(unittest.TestCase): expected = {} expected['reason'] = content.Content( content_type.ContentType("text", "plain"), - lambda:[""]) + lambda:[_b("")]) found = parser.get_details("skip") self.assertEqual(expected, found) @@ -78,7 +78,7 @@ class TestSimpleDetails(unittest.TestCase): expected = {} expected['message'] = content.Content( content_type.ContentType("text", "plain"), - lambda:[""]) + lambda:[_b("")]) found = parser.get_details("success") self.assertEqual(expected, found) diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index 8171696..5541653 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -18,7 +18,7 @@ import datetime import unittest import os -from testtools.compat import _u, StringIO +from testtools.compat import _b, _u, StringIO from testtools.content import Content, TracebackContent from testtools.content_type import ContentType from testtools.tests.helpers import ( @@ -372,8 +372,8 @@ class TestInTestMultipart(unittest.TestCase): def setUp(self): self.client = ExtendedTestResult() self.protocol = subunit.TestProtocolServer(self.client) - self.protocol.lineReceived("test mcdonalds farm\n") - self.test = subunit.RemotedTestCase("mcdonalds farm") + self.protocol.lineReceived(_b("test mcdonalds farm\n")) + self.test = subunit.RemotedTestCase(_u("mcdonalds farm")) def test__outcome_sets_details_parser(self): self.protocol._reading_success_details.details_parser = None @@ -770,13 +770,13 @@ class TestTestProtocolServerStreamTags(unittest.TestCase): ], self.client._events) def test_tags_do_not_get_set_on_test(self): - self.protocol.lineReceived("test mcdonalds farm\n") + self.protocol.lineReceived(_b("test mcdonalds farm\n")) test = self.client._events[0][-1] self.assertEqual(None, getattr(test, 'tags', None)) def test_tags_do_not_get_set_on_global_tags(self): - self.protocol.lineReceived("tags: foo bar\n") - self.protocol.lineReceived("test mcdonalds farm\n") + self.protocol.lineReceived(_b("tags: foo bar\n")) + self.protocol.lineReceived(_b("test mcdonalds farm\n")) test = self.client._events[-1][-1] self.assertEqual(None, getattr(test, 'tags', None)) @@ -884,7 +884,7 @@ class TestExecTestCase(unittest.TestCase): bing = subunit.RemotedTestCase("bing crosby") bing_details = {} bing_details['traceback'] = Content(ContentType("text", "x-traceback", - {'charset': 'utf8'}), lambda:["foo.c:53:ERROR invalid state\n"]) + {'charset': 'utf8'}), lambda:[_b("foo.c:53:ERROR invalid state\n")]) an_error = subunit.RemotedTestCase("an error") error_details = {} self.assertEqual([ -- cgit v1.2.1 From 970fe166268ac41a20aa6dc78e4c491ae5449173 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Mon, 25 Apr 2011 11:19:53 +1200 Subject: More small stuff. --- python/subunit/tests/test_test_protocol.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index 5541653..9152cce 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -18,7 +18,7 @@ import datetime import unittest import os -from testtools.compat import _b, _u, StringIO +from testtools.compat import _b, _u, BytesIO, StringIO from testtools.content import Content, TracebackContent from testtools.content_type import ContentType from testtools.tests.helpers import ( @@ -55,23 +55,23 @@ class TestProtocolServerForward(unittest.TestCase): def test_story(self): client = unittest.TestResult() - out = StringIO() + out = BytesIO() protocol = subunit.TestProtocolServer(client, forward_stream=out) - pipe = StringIO("test old mcdonald\n" - "success old mcdonald\n") + pipe = BytesIO(_b("test old mcdonald\n" + "success old mcdonald\n")) protocol.readFrom(pipe) self.assertEqual(client.testsRun, 1) self.assertEqual(pipe.getvalue(), out.getvalue()) def test_not_command(self): client = unittest.TestResult() - out = StringIO() + out = BytesIO() protocol = subunit.TestProtocolServer(client, stream=subunit.DiscardStream(), forward_stream=out) - pipe = StringIO("success old mcdonald\n") + pipe = BytesIO(_b("success old mcdonald\n")) protocol.readFrom(pipe) self.assertEqual(client.testsRun, 0) - self.assertEqual("", out.getvalue()) + self.assertEqual(_b(""), out.getvalue()) class TestTestProtocolServerPipe(unittest.TestCase): -- cgit v1.2.1 From d8df52062fbcee4da77b6e1cdb701defa2e8a2da Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Mon, 25 Apr 2011 12:40:59 +1200 Subject: More fixups. --- python/subunit/tests/test_test_protocol.py | 269 +++++++++++++++-------------- 1 file changed, 135 insertions(+), 134 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index 9152cce..7778fcc 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -79,14 +79,14 @@ class TestTestProtocolServerPipe(unittest.TestCase): def test_story(self): client = unittest.TestResult() protocol = subunit.TestProtocolServer(client) - pipe = StringIO("test old mcdonald\n" + pipe = BytesIO(_b("test old mcdonald\n" "success old mcdonald\n" "test bing crosby\n" "failure bing crosby [\n" "foo.c:53:ERROR invalid state\n" "]\n" "test an error\n" - "error an error\n") + "error an error\n")) protocol.readFrom(pipe) bing = subunit.RemotedTestCase("bing crosby") an_error = subunit.RemotedTestCase("an error") @@ -110,26 +110,26 @@ class TestTestProtocolServerStartTest(unittest.TestCase): self.protocol = subunit.TestProtocolServer(self.client) def test_start_test(self): - self.protocol.lineReceived("test old mcdonald\n") + self.protocol.lineReceived(_b("test old mcdonald\n")) self.assertEqual(self.client._events, [('startTest', subunit.RemotedTestCase("old mcdonald"))]) def test_start_testing(self): - self.protocol.lineReceived("testing old mcdonald\n") + self.protocol.lineReceived(_b("testing old mcdonald\n")) self.assertEqual(self.client._events, [('startTest', subunit.RemotedTestCase("old mcdonald"))]) def test_start_test_colon(self): - self.protocol.lineReceived("test: old mcdonald\n") + self.protocol.lineReceived(_b("test: old mcdonald\n")) self.assertEqual(self.client._events, [('startTest', subunit.RemotedTestCase("old mcdonald"))]) def test_indented_test_colon_ignored(self): - self.protocol.lineReceived(" test: old mcdonald\n") + self.protocol.lineReceived(_b(" test: old mcdonald\n")) self.assertEqual([], self.client._events) def test_start_testing_colon(self): - self.protocol.lineReceived("testing: old mcdonald\n") + self.protocol.lineReceived(_b("testing: old mcdonald\n")) self.assertEqual(self.client._events, [('startTest', subunit.RemotedTestCase("old mcdonald"))]) @@ -137,22 +137,22 @@ class TestTestProtocolServerStartTest(unittest.TestCase): class TestTestProtocolServerPassThrough(unittest.TestCase): def setUp(self): - self.stdout = StringIO() + self.stdout = BytesIO() self.test = subunit.RemotedTestCase("old mcdonald") self.client = ExtendedTestResult() self.protocol = subunit.TestProtocolServer(self.client, self.stdout) def keywords_before_test(self): - self.protocol.lineReceived("failure a\n") - self.protocol.lineReceived("failure: a\n") - self.protocol.lineReceived("error a\n") - self.protocol.lineReceived("error: a\n") - self.protocol.lineReceived("success a\n") - self.protocol.lineReceived("success: a\n") - self.protocol.lineReceived("successful a\n") - self.protocol.lineReceived("successful: a\n") - self.protocol.lineReceived("]\n") - self.assertEqual(self.stdout.getvalue(), "failure a\n" + self.protocol.lineReceived(_b("failure a\n")) + self.protocol.lineReceived(_b("failure: a\n")) + self.protocol.lineReceived(_b("error a\n")) + self.protocol.lineReceived(_b("error: a\n")) + self.protocol.lineReceived(_b("success a\n")) + self.protocol.lineReceived(_b("success: a\n")) + self.protocol.lineReceived(_b("successful a\n")) + self.protocol.lineReceived(_b("successful: a\n")) + self.protocol.lineReceived(_b("]\n")) + self.assertEqual(self.stdout.getvalue(), _b("failure a\n" "failure: a\n" "error a\n" "error: a\n" @@ -160,15 +160,15 @@ class TestTestProtocolServerPassThrough(unittest.TestCase): "success: a\n" "successful a\n" "successful: a\n" - "]\n") + "]\n")) def test_keywords_before_test(self): self.keywords_before_test() self.assertEqual(self.client._events, []) def test_keywords_after_error(self): - self.protocol.lineReceived("test old mcdonald\n") - self.protocol.lineReceived("error old mcdonald\n") + self.protocol.lineReceived(_b("test old mcdonald\n")) + self.protocol.lineReceived(_b("error old mcdonald\n")) self.keywords_before_test() self.assertEqual([ ('startTest', self.test), @@ -177,8 +177,8 @@ class TestTestProtocolServerPassThrough(unittest.TestCase): ], self.client._events) def test_keywords_after_failure(self): - self.protocol.lineReceived("test old mcdonald\n") - self.protocol.lineReceived("failure old mcdonald\n") + self.protocol.lineReceived(_b("test old mcdonald\n")) + self.protocol.lineReceived(_b("failure old mcdonald\n")) self.keywords_before_test() self.assertEqual(self.client._events, [ ('startTest', self.test), @@ -187,8 +187,8 @@ class TestTestProtocolServerPassThrough(unittest.TestCase): ]) def test_keywords_after_success(self): - self.protocol.lineReceived("test old mcdonald\n") - self.protocol.lineReceived("success old mcdonald\n") + self.protocol.lineReceived(_b("test old mcdonald\n")) + self.protocol.lineReceived(_b("success old mcdonald\n")) self.keywords_before_test() self.assertEqual([ ('startTest', self.test), @@ -197,19 +197,19 @@ class TestTestProtocolServerPassThrough(unittest.TestCase): ], self.client._events) def test_keywords_after_test(self): - self.protocol.lineReceived("test old mcdonald\n") - self.protocol.lineReceived("test old mcdonald\n") - self.protocol.lineReceived("failure a\n") - self.protocol.lineReceived("failure: a\n") - self.protocol.lineReceived("error a\n") - self.protocol.lineReceived("error: a\n") - self.protocol.lineReceived("success a\n") - self.protocol.lineReceived("success: a\n") - self.protocol.lineReceived("successful a\n") - self.protocol.lineReceived("successful: a\n") - self.protocol.lineReceived("]\n") - self.protocol.lineReceived("failure old mcdonald\n") - self.assertEqual(self.stdout.getvalue(), "test old mcdonald\n" + self.protocol.lineReceived(_b("test old mcdonald\n")) + self.protocol.lineReceived(_b("test old mcdonald\n")) + self.protocol.lineReceived(_b("failure a\n")) + self.protocol.lineReceived(_b("failure: a\n")) + self.protocol.lineReceived(_b("error a\n")) + self.protocol.lineReceived(_b("error: a\n")) + self.protocol.lineReceived(_b("success a\n")) + self.protocol.lineReceived(_b("success: a\n")) + self.protocol.lineReceived(_b("successful a\n")) + self.protocol.lineReceived(_b("successful: a\n")) + self.protocol.lineReceived(_b("]\n")) + self.protocol.lineReceived(_b("failure old mcdonald\n")) + self.assertEqual(self.stdout.getvalue(), _b("test old mcdonald\n" "failure a\n" "failure: a\n" "error a\n" @@ -218,7 +218,7 @@ class TestTestProtocolServerPassThrough(unittest.TestCase): "success: a\n" "successful a\n" "successful: a\n" - "]\n") + "]\n")) self.assertEqual(self.client._events, [ ('startTest', self.test), ('addFailure', self.test, {}), @@ -228,24 +228,24 @@ class TestTestProtocolServerPassThrough(unittest.TestCase): def test_keywords_during_failure(self): # A smoke test to make sure that the details parsers have control # appropriately. - self.protocol.lineReceived("test old mcdonald\n") - self.protocol.lineReceived("failure: old mcdonald [\n") - self.protocol.lineReceived("test old mcdonald\n") - self.protocol.lineReceived("failure a\n") - self.protocol.lineReceived("failure: a\n") - self.protocol.lineReceived("error a\n") - self.protocol.lineReceived("error: a\n") - self.protocol.lineReceived("success a\n") - self.protocol.lineReceived("success: a\n") - self.protocol.lineReceived("successful a\n") - self.protocol.lineReceived("successful: a\n") - self.protocol.lineReceived(" ]\n") - self.protocol.lineReceived("]\n") - self.assertEqual(self.stdout.getvalue(), "") + self.protocol.lineReceived(_b("test old mcdonald\n")) + self.protocol.lineReceived(_b("failure: old mcdonald [\n")) + self.protocol.lineReceived(_b("test old mcdonald\n")) + self.protocol.lineReceived(_b("failure a\n")) + self.protocol.lineReceived(_b("failure: a\n")) + self.protocol.lineReceived(_b("error a\n")) + self.protocol.lineReceived(_b("error: a\n")) + self.protocol.lineReceived(_b("success a\n")) + self.protocol.lineReceived(_b("success: a\n")) + self.protocol.lineReceived(_b("successful a\n")) + self.protocol.lineReceived(_b("successful: a\n")) + self.protocol.lineReceived(_b(" ]\n")) + self.protocol.lineReceived(_b("]\n")) + self.assertEqual(self.stdout.getvalue(), _b("")) details = {} details['traceback'] = Content(ContentType("text", "x-traceback", {'charset': 'utf8'}), - lambda:[ + lambda:[_b( "test old mcdonald\n" "failure a\n" "failure: a\n" @@ -255,7 +255,7 @@ class TestTestProtocolServerPassThrough(unittest.TestCase): "success: a\n" "successful a\n" "successful: a\n" - "]\n"]) + "]\n")]) self.assertEqual(self.client._events, [ ('startTest', self.test), ('addFailure', self.test, details), @@ -266,7 +266,7 @@ class TestTestProtocolServerPassThrough(unittest.TestCase): """Lines received which cannot be interpreted as any protocol action should be passed through to sys.stdout. """ - bytes = "randombytes\n" + bytes = _b("randombytes\n") self.protocol.lineReceived(bytes) self.assertEqual(self.stdout.getvalue(), bytes) @@ -283,7 +283,7 @@ class TestTestProtocolServerLostConnection(unittest.TestCase): self.assertEqual([], self.client._events) def test_lost_connection_after_start(self): - self.protocol.lineReceived("test old mcdonald\n") + self.protocol.lineReceived(_b("test old mcdonald\n")) self.protocol.lostConnection() failure = subunit.RemoteError( _u("lost connection during test 'old mcdonald'")) @@ -294,8 +294,8 @@ class TestTestProtocolServerLostConnection(unittest.TestCase): ], self.client._events) def test_lost_connected_after_error(self): - self.protocol.lineReceived("test old mcdonald\n") - self.protocol.lineReceived("error old mcdonald\n") + self.protocol.lineReceived(_b("test old mcdonald\n")) + self.protocol.lineReceived(_b("error old mcdonald\n")) self.protocol.lostConnection() self.assertEqual([ ('startTest', self.test), @@ -304,8 +304,8 @@ class TestTestProtocolServerLostConnection(unittest.TestCase): ], self.client._events) def do_connection_lost(self, outcome, opening): - self.protocol.lineReceived("test old mcdonald\n") - self.protocol.lineReceived("%s old mcdonald %s" % (outcome, opening)) + self.protocol.lineReceived(_b("test old mcdonald\n")) + self.protocol.lineReceived(_b("%s old mcdonald %s" % (outcome, opening))) self.protocol.lostConnection() failure = subunit.RemoteError( _u("lost connection during %s report of test 'old mcdonald'") % @@ -323,8 +323,8 @@ class TestTestProtocolServerLostConnection(unittest.TestCase): self.do_connection_lost("error", "[ multipart\n") def test_lost_connected_after_failure(self): - self.protocol.lineReceived("test old mcdonald\n") - self.protocol.lineReceived("failure old mcdonald\n") + self.protocol.lineReceived(_b("test old mcdonald\n")) + self.protocol.lineReceived(_b("failure old mcdonald\n")) self.protocol.lostConnection() self.assertEqual([ ('startTest', self.test), @@ -339,8 +339,8 @@ class TestTestProtocolServerLostConnection(unittest.TestCase): self.do_connection_lost("failure", "[ multipart\n") def test_lost_connection_after_success(self): - self.protocol.lineReceived("test old mcdonald\n") - self.protocol.lineReceived("success old mcdonald\n") + self.protocol.lineReceived(_b("test old mcdonald\n")) + self.protocol.lineReceived(_b("success old mcdonald\n")) self.protocol.lostConnection() self.assertEqual([ ('startTest', self.test), @@ -377,7 +377,7 @@ class TestInTestMultipart(unittest.TestCase): def test__outcome_sets_details_parser(self): self.protocol._reading_success_details.details_parser = None - self.protocol._state._outcome(0, "mcdonalds farm [ multipart\n", + self.protocol._state._outcome(0, _b("mcdonalds farm [ multipart\n"), None, self.protocol._reading_success_details) parser = self.protocol._reading_success_details.details_parser self.assertNotEqual(None, parser) @@ -390,11 +390,11 @@ class TestTestProtocolServerAddError(unittest.TestCase): def setUp(self): self.client = ExtendedTestResult() self.protocol = subunit.TestProtocolServer(self.client) - self.protocol.lineReceived("test mcdonalds farm\n") + self.protocol.lineReceived(_b("test mcdonalds farm\n")) self.test = subunit.RemotedTestCase("mcdonalds farm") def simple_error_keyword(self, keyword): - self.protocol.lineReceived("%s mcdonalds farm\n" % keyword) + self.protocol.lineReceived(_b("%s mcdonalds farm\n" % keyword)) details = {} self.assertEqual([ ('startTest', self.test), @@ -409,11 +409,11 @@ class TestTestProtocolServerAddError(unittest.TestCase): self.simple_error_keyword("error:") def test_error_empty_message(self): - self.protocol.lineReceived("error mcdonalds farm [\n") - self.protocol.lineReceived("]\n") + self.protocol.lineReceived(_b("error mcdonalds farm [\n")) + self.protocol.lineReceived(_b("]\n")) details = {} details['traceback'] = Content(ContentType("text", "x-traceback", - {'charset': 'utf8'}), lambda:[""]) + {'charset': 'utf8'}), lambda:[_b("")]) self.assertEqual([ ('startTest', self.test), ('addError', self.test, details), @@ -421,12 +421,12 @@ class TestTestProtocolServerAddError(unittest.TestCase): ], self.client._events) def error_quoted_bracket(self, keyword): - self.protocol.lineReceived("%s mcdonalds farm [\n" % keyword) - self.protocol.lineReceived(" ]\n") - self.protocol.lineReceived("]\n") + self.protocol.lineReceived(_b("%s mcdonalds farm [\n" % keyword)) + self.protocol.lineReceived(_b(" ]\n")) + self.protocol.lineReceived(_b("]\n")) details = {} details['traceback'] = Content(ContentType("text", "x-traceback", - {'charset': 'utf8'}), lambda:["]\n"]) + {'charset': 'utf8'}), lambda:[_b("]\n")]) self.assertEqual([ ('startTest', self.test), ('addError', self.test, details), @@ -445,7 +445,7 @@ class TestTestProtocolServerAddFailure(unittest.TestCase): def setUp(self): self.client = ExtendedTestResult() self.protocol = subunit.TestProtocolServer(self.client) - self.protocol.lineReceived("test mcdonalds farm\n") + self.protocol.lineReceived(_b("test mcdonalds farm\n")) self.test = subunit.RemotedTestCase("mcdonalds farm") def assertFailure(self, details): @@ -456,7 +456,7 @@ class TestTestProtocolServerAddFailure(unittest.TestCase): ], self.client._events) def simple_failure_keyword(self, keyword): - self.protocol.lineReceived("%s mcdonalds farm\n" % keyword) + self.protocol.lineReceived(_b("%s mcdonalds farm\n" % keyword)) details = {} self.assertFailure(details) @@ -467,20 +467,20 @@ class TestTestProtocolServerAddFailure(unittest.TestCase): self.simple_failure_keyword("failure:") def test_failure_empty_message(self): - self.protocol.lineReceived("failure mcdonalds farm [\n") - self.protocol.lineReceived("]\n") + self.protocol.lineReceived(_b("failure mcdonalds farm [\n")) + self.protocol.lineReceived(_b("]\n")) details = {} details['traceback'] = Content(ContentType("text", "x-traceback", - {'charset': 'utf8'}), lambda:[""]) + {'charset': 'utf8'}), lambda:[_b("")]) self.assertFailure(details) def failure_quoted_bracket(self, keyword): - self.protocol.lineReceived("%s mcdonalds farm [\n" % keyword) - self.protocol.lineReceived(" ]\n") - self.protocol.lineReceived("]\n") + self.protocol.lineReceived(_b("%s mcdonalds farm [\n" % keyword)) + self.protocol.lineReceived(_b(" ]\n")) + self.protocol.lineReceived(_b("]\n")) details = {} details['traceback'] = Content(ContentType("text", "x-traceback", - {'charset': 'utf8'}), lambda:["]\n"]) + {'charset': 'utf8'}), lambda:[_b("]\n")]) self.assertFailure(details) def test_failure_quoted_bracket(self): @@ -518,11 +518,11 @@ class TestTestProtocolServerAddxFail(unittest.TestCase): def setup_protocol(self): """Setup the protocol based on self.client.""" self.protocol = subunit.TestProtocolServer(self.client) - self.protocol.lineReceived("test mcdonalds farm\n") + self.protocol.lineReceived(_b("test mcdonalds farm\n")) self.test = self.client._events[-1][-1] def simple_xfail_keyword(self, keyword, as_success): - self.protocol.lineReceived("%s mcdonalds farm\n" % keyword) + self.protocol.lineReceived(_b("%s mcdonalds farm\n" % keyword)) self.check_success_or_xfail(as_success) def check_success_or_xfail(self, as_success, error_message=None): @@ -537,13 +537,14 @@ class TestTestProtocolServerAddxFail(unittest.TestCase): if error_message is not None: details['traceback'] = Content( ContentType("text", "x-traceback", {'charset': 'utf8'}), - lambda:[error_message]) + lambda:[_b(error_message)]) if isinstance(self.client, ExtendedTestResult): value = details else: if error_message is not None: value = subunit.RemoteError(_u("Text attachment: traceback\n" - "------------\n") + error_message + _u("------------\n")) + "------------\n") + _u(error_message) + + _u("------------\n")) else: value = subunit.RemoteError() self.assertEqual([ @@ -577,16 +578,16 @@ class TestTestProtocolServerAddxFail(unittest.TestCase): self.empty_message(False, error_message="") def empty_message(self, as_success, error_message="\n"): - self.protocol.lineReceived("xfail mcdonalds farm [\n") - self.protocol.lineReceived("]\n") + self.protocol.lineReceived(_b("xfail mcdonalds farm [\n")) + self.protocol.lineReceived(_b("]\n")) self.check_success_or_xfail(as_success, error_message) def xfail_quoted_bracket(self, keyword, as_success): # This tests it is accepted, but cannot test it is used today, because # of not having a way to expose it in Python so far. - self.protocol.lineReceived("%s mcdonalds farm [\n" % keyword) - self.protocol.lineReceived(" ]\n") - self.protocol.lineReceived("]\n") + self.protocol.lineReceived(_b("%s mcdonalds farm [\n" % keyword)) + self.protocol.lineReceived(_b(" ]\n")) + self.protocol.lineReceived(_b("]\n")) self.check_success_or_xfail(as_success, "]\n") def test_xfail_quoted_bracket(self): @@ -617,7 +618,7 @@ class TestTestProtocolServerAddSkip(unittest.TestCase): """Setup a test object ready to be skipped.""" self.client = ExtendedTestResult() self.protocol = subunit.TestProtocolServer(self.client) - self.protocol.lineReceived("test mcdonalds farm\n") + self.protocol.lineReceived(_b("test mcdonalds farm\n")) self.test = self.client._events[-1][-1] def assertSkip(self, reason): @@ -632,7 +633,7 @@ class TestTestProtocolServerAddSkip(unittest.TestCase): ], self.client._events) def simple_skip_keyword(self, keyword): - self.protocol.lineReceived("%s mcdonalds farm\n" % keyword) + self.protocol.lineReceived(_b("%s mcdonalds farm\n" % keyword)) self.assertSkip(None) def test_simple_skip(self): @@ -642,17 +643,17 @@ class TestTestProtocolServerAddSkip(unittest.TestCase): self.simple_skip_keyword("skip:") def test_skip_empty_message(self): - self.protocol.lineReceived("skip mcdonalds farm [\n") - self.protocol.lineReceived("]\n") - self.assertSkip("") + self.protocol.lineReceived(_b("skip mcdonalds farm [\n")) + self.protocol.lineReceived(_b("]\n")) + self.assertSkip(_b("")) def skip_quoted_bracket(self, keyword): # This tests it is accepted, but cannot test it is used today, because # of not having a way to expose it in Python so far. - self.protocol.lineReceived("%s mcdonalds farm [\n" % keyword) - self.protocol.lineReceived(" ]\n") - self.protocol.lineReceived("]\n") - self.assertSkip("]\n") + self.protocol.lineReceived(_b("%s mcdonalds farm [\n" % keyword)) + self.protocol.lineReceived(_b(" ]\n")) + self.protocol.lineReceived(_b("]\n")) + self.assertSkip(_b("]\n")) def test_skip_quoted_bracket(self): self.skip_quoted_bracket("skip") @@ -666,11 +667,11 @@ class TestTestProtocolServerAddSuccess(unittest.TestCase): def setUp(self): self.client = ExtendedTestResult() self.protocol = subunit.TestProtocolServer(self.client) - self.protocol.lineReceived("test mcdonalds farm\n") + self.protocol.lineReceived(_b("test mcdonalds farm\n")) self.test = subunit.RemotedTestCase("mcdonalds farm") def simple_success_keyword(self, keyword): - self.protocol.lineReceived("%s mcdonalds farm\n" % keyword) + self.protocol.lineReceived(_b("%s mcdonalds farm\n" % keyword)) self.assertEqual([ ('startTest', self.test), ('addSuccess', self.test), @@ -691,22 +692,22 @@ class TestTestProtocolServerAddSuccess(unittest.TestCase): ], self.client._events) def test_success_empty_message(self): - self.protocol.lineReceived("success mcdonalds farm [\n") - self.protocol.lineReceived("]\n") + self.protocol.lineReceived(_b("success mcdonalds farm [\n")) + self.protocol.lineReceived(_b("]\n")) details = {} details['message'] = Content(ContentType("text", "plain"), - lambda:[""]) + lambda:[_b("")]) self.assertSuccess(details) def success_quoted_bracket(self, keyword): # This tests it is accepted, but cannot test it is used today, because # of not having a way to expose it in Python so far. - self.protocol.lineReceived("%s mcdonalds farm [\n" % keyword) - self.protocol.lineReceived(" ]\n") - self.protocol.lineReceived("]\n") + self.protocol.lineReceived(_b("%s mcdonalds farm [\n" % keyword)) + self.protocol.lineReceived(_b(" ]\n")) + self.protocol.lineReceived(_b("]\n")) details = {} details['message'] = Content(ContentType("text", "plain"), - lambda:["]\n"]) + lambda:[_b("]\n")]) self.assertSuccess(details) def test_success_quoted_bracket(self): @@ -721,26 +722,26 @@ class TestTestProtocolServerProgress(unittest.TestCase): def test_progress_accepted_stdlib(self): self.result = Python26TestResult() - self.stream = StringIO() + self.stream = BytesIO() self.protocol = subunit.TestProtocolServer(self.result, stream=self.stream) - self.protocol.lineReceived("progress: 23") - self.protocol.lineReceived("progress: -2") - self.protocol.lineReceived("progress: +4") - self.assertEqual("", self.stream.getvalue()) + self.protocol.lineReceived(_b("progress: 23")) + self.protocol.lineReceived(_b("progress: -2")) + self.protocol.lineReceived(_b("progress: +4")) + self.assertEqual(_b(""), self.stream.getvalue()) def test_progress_accepted_extended(self): # With a progress capable TestResult, progress events are emitted. self.result = ExtendedTestResult() - self.stream = StringIO() + self.stream = BytesIO() self.protocol = subunit.TestProtocolServer(self.result, stream=self.stream) - self.protocol.lineReceived("progress: 23") - self.protocol.lineReceived("progress: push") - self.protocol.lineReceived("progress: -2") - self.protocol.lineReceived("progress: pop") - self.protocol.lineReceived("progress: +4") - self.assertEqual("", self.stream.getvalue()) + self.protocol.lineReceived(_b("progress: 23")) + self.protocol.lineReceived(_b("progress: push")) + self.protocol.lineReceived(_b("progress: -2")) + self.protocol.lineReceived(_b("progress: pop")) + self.protocol.lineReceived(_b("progress: +4")) + self.assertEqual(_b(""), self.stream.getvalue()) self.assertEqual([ ('progress', 23, subunit.PROGRESS_SET), ('progress', None, subunit.PROGRESS_PUSH), @@ -758,13 +759,13 @@ class TestTestProtocolServerStreamTags(unittest.TestCase): self.protocol = subunit.TestProtocolServer(self.client) def test_initial_tags(self): - self.protocol.lineReceived("tags: foo bar:baz quux\n") + self.protocol.lineReceived(_b("tags: foo bar:baz quux\n")) self.assertEqual([ ('tags', set(["foo", "bar:baz", "quux"]), set()), ], self.client._events) def test_minus_removes_tags(self): - self.protocol.lineReceived("tags: -bar quux\n") + self.protocol.lineReceived(_b("tags: -bar quux\n")) self.assertEqual([ ('tags', set(["quux"]), set(["bar"])), ], self.client._events) @@ -781,10 +782,10 @@ class TestTestProtocolServerStreamTags(unittest.TestCase): self.assertEqual(None, getattr(test, 'tags', None)) def test_tags_get_set_on_test_tags(self): - self.protocol.lineReceived("test mcdonalds farm\n") + self.protocol.lineReceived(_b("test mcdonalds farm\n")) test = self.client._events[-1][-1] - self.protocol.lineReceived("tags: foo bar\n") - self.protocol.lineReceived("success mcdonalds farm\n") + self.protocol.lineReceived(_b("tags: foo bar\n")) + self.protocol.lineReceived(_b("success mcdonalds farm\n")) self.assertEqual(None, getattr(test, 'tags', None)) @@ -793,19 +794,19 @@ class TestTestProtocolServerStreamTime(unittest.TestCase): def test_time_accepted_stdlib(self): self.result = Python26TestResult() - self.stream = StringIO() + self.stream = BytesIO() self.protocol = subunit.TestProtocolServer(self.result, stream=self.stream) - self.protocol.lineReceived("time: 2001-12-12 12:59:59Z\n") - self.assertEqual("", self.stream.getvalue()) + self.protocol.lineReceived(_b("time: 2001-12-12 12:59:59Z\n")) + self.assertEqual(_b(""), self.stream.getvalue()) def test_time_accepted_extended(self): self.result = ExtendedTestResult() - self.stream = StringIO() + self.stream = BytesIO() self.protocol = subunit.TestProtocolServer(self.result, stream=self.stream) - self.protocol.lineReceived("time: 2001-12-12 12:59:59Z\n") - self.assertEqual("", self.stream.getvalue()) + self.protocol.lineReceived(_b("time: 2001-12-12 12:59:59Z\n")) + self.assertEqual(_b(""), self.stream.getvalue()) self.assertEqual([ ('time', datetime.datetime(2001, 12, 12, 12, 59, 59, 0, iso8601.Utc())) -- cgit v1.2.1 From abc703874bcbabc890ffb8d23264a4d2095d72a6 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Mon, 25 Apr 2011 13:29:31 +1200 Subject: Update stats tests. --- python/subunit/tests/test_subunit_stats.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_subunit_stats.py b/python/subunit/tests/test_subunit_stats.py index 778bb7f..6fd3301 100644 --- a/python/subunit/tests/test_subunit_stats.py +++ b/python/subunit/tests/test_subunit_stats.py @@ -18,7 +18,7 @@ import unittest -from testtools.compat import StringIO +from testtools.compat import _b, BytesIO, StringIO import subunit @@ -29,7 +29,7 @@ class TestTestResultStats(unittest.TestCase): def setUp(self): self.output = StringIO() self.result = subunit.TestResultStats(self.output) - self.input_stream = StringIO() + self.input_stream = BytesIO() self.test = subunit.ProtocolTestCase(self.input_stream) def test_stats_empty(self): @@ -40,7 +40,7 @@ class TestTestResultStats(unittest.TestCase): self.assertEqual(set(), self.result.seen_tags) def setUpUsedStream(self): - self.input_stream.write("""tags: global + self.input_stream.write(_b("""tags: global test passed success passed test failed @@ -52,7 +52,7 @@ test skipped skip skipped test todo xfail todo -""") +""")) self.input_stream.seek(0) self.test.run(self.result) -- cgit v1.2.1 From 86b85e3f83f4030a63026386ffc3d3488ab34d13 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Mon, 25 Apr 2011 16:25:24 +1200 Subject: Nearly done. --- python/subunit/tests/test_chunked.py | 98 ++++++++++++++--------------- python/subunit/tests/test_details.py | 16 ++--- python/subunit/tests/test_subunit_filter.py | 12 ++-- python/subunit/tests/test_test_protocol.py | 79 +++++++++++------------ 4 files changed, 101 insertions(+), 104 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_chunked.py b/python/subunit/tests/test_chunked.py index 6323b02..e0742f1 100644 --- a/python/subunit/tests/test_chunked.py +++ b/python/subunit/tests/test_chunked.py @@ -17,7 +17,7 @@ import unittest -from testtools.compat import StringIO +from testtools.compat import _b, BytesIO import subunit.chunked @@ -32,121 +32,121 @@ class TestDecode(unittest.TestCase): def setUp(self): unittest.TestCase.setUp(self) - self.output = StringIO() + self.output = BytesIO() self.decoder = subunit.chunked.Decoder(self.output) def test_close_read_length_short_errors(self): self.assertRaises(ValueError, self.decoder.close) def test_close_body_short_errors(self): - self.assertEqual(None, self.decoder.write('2\r\na')) + self.assertEqual(None, self.decoder.write(_b('2\r\na'))) self.assertRaises(ValueError, self.decoder.close) def test_close_body_buffered_data_errors(self): - self.assertEqual(None, self.decoder.write('2\r')) + self.assertEqual(None, self.decoder.write(_b('2\r'))) self.assertRaises(ValueError, self.decoder.close) def test_close_after_finished_stream_safe(self): - self.assertEqual(None, self.decoder.write('2\r\nab')) - self.assertEqual('', self.decoder.write('0\r\n')) + self.assertEqual(None, self.decoder.write(_b('2\r\nab'))) + self.assertEqual(_b(''), self.decoder.write(_b('0\r\n'))) self.decoder.close() def test_decode_nothing(self): - self.assertEqual('', self.decoder.write('0\r\n')) - self.assertEqual('', self.output.getvalue()) + self.assertEqual(_b(''), self.decoder.write(_b('0\r\n'))) + self.assertEqual(_b(''), self.output.getvalue()) def test_decode_serialised_form(self): - self.assertEqual(None, self.decoder.write("F\r\n")) - self.assertEqual(None, self.decoder.write("serialised\n")) - self.assertEqual('', self.decoder.write("form0\r\n")) + self.assertEqual(None, self.decoder.write(_b("F\r\n"))) + self.assertEqual(None, self.decoder.write(_b("serialised\n"))) + self.assertEqual(_b(''), self.decoder.write(_b("form0\r\n"))) def test_decode_short(self): - self.assertEqual('', self.decoder.write('3\r\nabc0\r\n')) - self.assertEqual('abc', self.output.getvalue()) + self.assertEqual(_b(''), self.decoder.write(_b('3\r\nabc0\r\n'))) + self.assertEqual(_b('abc'), self.output.getvalue()) def test_decode_combines_short(self): - self.assertEqual('', self.decoder.write('6\r\nabcdef0\r\n')) - self.assertEqual('abcdef', self.output.getvalue()) + self.assertEqual(_b(''), self.decoder.write(_b('6\r\nabcdef0\r\n'))) + self.assertEqual(_b('abcdef'), self.output.getvalue()) def test_decode_excess_bytes_from_write(self): - self.assertEqual('1234', self.decoder.write('3\r\nabc0\r\n1234')) - self.assertEqual('abc', self.output.getvalue()) + self.assertEqual(_b('1234'), self.decoder.write(_b('3\r\nabc0\r\n1234'))) + self.assertEqual(_b('abc'), self.output.getvalue()) def test_decode_write_after_finished_errors(self): - self.assertEqual('1234', self.decoder.write('3\r\nabc0\r\n1234')) - self.assertRaises(ValueError, self.decoder.write, '') + self.assertEqual(_b('1234'), self.decoder.write(_b('3\r\nabc0\r\n1234'))) + self.assertRaises(ValueError, self.decoder.write, _b('')) def test_decode_hex(self): - self.assertEqual('', self.decoder.write('A\r\n12345678900\r\n')) - self.assertEqual('1234567890', self.output.getvalue()) + self.assertEqual(_b(''), self.decoder.write(_b('A\r\n12345678900\r\n'))) + self.assertEqual(_b('1234567890'), self.output.getvalue()) def test_decode_long_ranges(self): - self.assertEqual(None, self.decoder.write('10000\r\n')) - self.assertEqual(None, self.decoder.write('1' * 65536)) - self.assertEqual(None, self.decoder.write('10000\r\n')) - self.assertEqual(None, self.decoder.write('2' * 65536)) - self.assertEqual('', self.decoder.write('0\r\n')) - self.assertEqual('1' * 65536 + '2' * 65536, self.output.getvalue()) + self.assertEqual(None, self.decoder.write(_b('10000\r\n'))) + self.assertEqual(None, self.decoder.write(_b('1' * 65536))) + self.assertEqual(None, self.decoder.write(_b('10000\r\n'))) + self.assertEqual(None, self.decoder.write(_b('2' * 65536))) + self.assertEqual(_b(''), self.decoder.write(_b('0\r\n'))) + self.assertEqual(_b('1' * 65536 + '2' * 65536), self.output.getvalue()) def test_decode_newline_nonstrict(self): """Tolerate chunk markers with no CR character.""" # From self.decoder = subunit.chunked.Decoder(self.output, strict=False) - self.assertEqual(None, self.decoder.write('a\n')) - self.assertEqual(None, self.decoder.write('abcdeabcde')) - self.assertEqual('', self.decoder.write('0\n')) - self.assertEqual('abcdeabcde', self.output.getvalue()) + self.assertEqual(None, self.decoder.write(_b('a\n'))) + self.assertEqual(None, self.decoder.write(_b('abcdeabcde'))) + self.assertEqual(_b(''), self.decoder.write(_b('0\n'))) + self.assertEqual(_b('abcdeabcde'), self.output.getvalue()) def test_decode_strict_newline_only(self): """Reject chunk markers with no CR character in strict mode.""" # From self.assertRaises(ValueError, - self.decoder.write, 'a\n') + self.decoder.write, _b('a\n')) def test_decode_strict_multiple_crs(self): self.assertRaises(ValueError, - self.decoder.write, 'a\r\r\n') + self.decoder.write, _b('a\r\r\n')) def test_decode_short_header(self): self.assertRaises(ValueError, - self.decoder.write, '\n') + self.decoder.write, _b('\n')) class TestEncode(unittest.TestCase): def setUp(self): unittest.TestCase.setUp(self) - self.output = StringIO() + self.output = BytesIO() self.encoder = subunit.chunked.Encoder(self.output) def test_encode_nothing(self): self.encoder.close() - self.assertEqual('0\r\n', self.output.getvalue()) + self.assertEqual(_b('0\r\n'), self.output.getvalue()) def test_encode_empty(self): - self.encoder.write('') + self.encoder.write(_b('')) self.encoder.close() - self.assertEqual('0\r\n', self.output.getvalue()) + self.assertEqual(_b('0\r\n'), self.output.getvalue()) def test_encode_short(self): - self.encoder.write('abc') + self.encoder.write(_b('abc')) self.encoder.close() - self.assertEqual('3\r\nabc0\r\n', self.output.getvalue()) + self.assertEqual(_b('3\r\nabc0\r\n'), self.output.getvalue()) def test_encode_combines_short(self): - self.encoder.write('abc') - self.encoder.write('def') + self.encoder.write(_b('abc')) + self.encoder.write(_b('def')) self.encoder.close() - self.assertEqual('6\r\nabcdef0\r\n', self.output.getvalue()) + self.assertEqual(_b('6\r\nabcdef0\r\n'), self.output.getvalue()) def test_encode_over_9_is_in_hex(self): - self.encoder.write('1234567890') + self.encoder.write(_b('1234567890')) self.encoder.close() - self.assertEqual('A\r\n12345678900\r\n', self.output.getvalue()) + self.assertEqual(_b('A\r\n12345678900\r\n'), self.output.getvalue()) def test_encode_long_ranges_not_combined(self): - self.encoder.write('1' * 65536) - self.encoder.write('2' * 65536) + self.encoder.write(_b('1' * 65536)) + self.encoder.write(_b('2' * 65536)) self.encoder.close() - self.assertEqual('10000\r\n' + '1' * 65536 + '10000\r\n' + - '2' * 65536 + '0\r\n', self.output.getvalue()) + self.assertEqual(_b('10000\r\n' + '1' * 65536 + '10000\r\n' + + '2' * 65536 + '0\r\n'), self.output.getvalue()) diff --git a/python/subunit/tests/test_details.py b/python/subunit/tests/test_details.py index 49010d2..746aa04 100644 --- a/python/subunit/tests/test_details.py +++ b/python/subunit/tests/test_details.py @@ -95,18 +95,18 @@ class TestMultipartDetails(unittest.TestCase): def test_parts(self): parser = details.MultipartDetailsParser(None) - parser.lineReceived("Content-Type: text/plain\n") - parser.lineReceived("something\n") - parser.lineReceived("F\r\n") - parser.lineReceived("serialised\n") - parser.lineReceived("form0\r\n") + parser.lineReceived(_b("Content-Type: text/plain\n")) + parser.lineReceived(_b("something\n")) + parser.lineReceived(_b("F\r\n")) + parser.lineReceived(_b("serialised\n")) + parser.lineReceived(_b("form0\r\n")) expected = {} expected['something'] = content.Content( content_type.ContentType("text", "plain"), - lambda:["serialised\nform"]) + lambda:[_b("serialised\nform")]) found = parser.get_details() self.assertEqual(expected.keys(), found.keys()) self.assertEqual(expected['something'].content_type, found['something'].content_type) - self.assertEqual(''.join(expected['something'].iter_bytes()), - ''.join(found['something'].iter_bytes())) + self.assertEqual(_b('').join(expected['something'].iter_bytes()), + _b('').join(found['something'].iter_bytes())) diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py index 682f726..fb6ffcd 100644 --- a/python/subunit/tests/test_subunit_filter.py +++ b/python/subunit/tests/test_subunit_filter.py @@ -21,7 +21,7 @@ from subunit import iso8601 import unittest from testtools import TestCase -from testtools.compat import StringIO +from testtools.compat import _b, BytesIO, StringIO from testtools.testresult.doubles import ExtendedTestResult import subunit @@ -35,7 +35,7 @@ class TestTestResultFilter(TestCase): # is an easy pithy way of getting a series of test objects to call into # the TestResult, and as TestResultFilter is intended for use with subunit # also has the benefit of detecting any interface skew issues. - example_subunit_stream = """\ + example_subunit_stream = _b("""\ tags: global test passed success passed @@ -50,7 +50,7 @@ test skipped skip skipped test todo xfail todo -""" +""") def run_tests(self, result_filter, input_stream=None): """Run tests through the given filter. @@ -61,7 +61,7 @@ xfail todo """ if input_stream is None: input_stream = self.example_subunit_stream - test = subunit.ProtocolTestCase(StringIO(input_stream)) + test = subunit.ProtocolTestCase(BytesIO(input_stream)) test.run(result_filter) def test_default(self): @@ -139,13 +139,13 @@ xfail todo date_a = datetime(year=2000, month=1, day=1, tzinfo=iso8601.UTC) date_b = datetime(year=2000, month=1, day=2, tzinfo=iso8601.UTC) date_c = datetime(year=2000, month=1, day=3, tzinfo=iso8601.UTC) - subunit_stream = '\n'.join([ + subunit_stream = _b('\n'.join([ "time: %s", "test: foo", "time: %s", "error: foo", "time: %s", - ""]) % (date_a, date_b, date_c) + ""]) % (date_a, date_b, date_c)) result = ExtendedTestResult() result_filter = TestResultFilter(result) self.run_tests(result_filter, subunit_stream) diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index 7778fcc..7ec7758 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -28,7 +28,7 @@ from testtools.tests.helpers import ( ) import subunit -from subunit import _remote_exception_str +from subunit import _remote_exception_str, _remote_exception_str_chunked import subunit.iso8601 as iso8601 @@ -994,11 +994,11 @@ class TestIsolatedTestSuite(unittest.TestCase): class TestTestProtocolClient(unittest.TestCase): def setUp(self): - self.io = StringIO() + self.io = BytesIO() self.protocol = subunit.TestProtocolClient(self.io) self.test = TestTestProtocolClient("test_start_test") self.sample_details = {'something':Content( - ContentType('text', 'plain'), lambda:['serialised\nform'])} + ContentType('text', 'plain'), lambda:[_b('serialised\nform')])} self.sample_tb_details = dict(self.sample_details) self.sample_tb_details['traceback'] = TracebackContent( subunit.RemoteError(_u("boo qux")), self.test) @@ -1006,27 +1006,27 @@ class TestTestProtocolClient(unittest.TestCase): def test_start_test(self): """Test startTest on a TestProtocolClient.""" self.protocol.startTest(self.test) - self.assertEqual(self.io.getvalue(), "test: %s\n" % self.test.id()) + self.assertEqual(self.io.getvalue(), _b("test: %s\n" % self.test.id())) def test_stop_test(self): # stopTest doesn't output anything. self.protocol.stopTest(self.test) - self.assertEqual(self.io.getvalue(), "") + self.assertEqual(self.io.getvalue(), _b("")) def test_add_success(self): """Test addSuccess on a TestProtocolClient.""" self.protocol.addSuccess(self.test) self.assertEqual( - self.io.getvalue(), "successful: %s\n" % self.test.id()) + self.io.getvalue(), _b("successful: %s\n" % self.test.id())) def test_add_success_details(self): """Test addSuccess on a TestProtocolClient with details.""" self.protocol.addSuccess(self.test, details=self.sample_details) self.assertEqual( - self.io.getvalue(), "successful: %s [ multipart\n" + self.io.getvalue(), _b("successful: %s [ multipart\n" "Content-Type: text/plain\n" "something\n" - "F\r\nserialised\nform0\r\n]\n" % self.test.id()) + "F\r\nserialised\nform0\r\n]\n" % self.test.id())) def test_add_failure(self): """Test addFailure on a TestProtocolClient.""" @@ -1034,8 +1034,8 @@ class TestTestProtocolClient(unittest.TestCase): self.test, subunit.RemoteError(_u("boo qux"))) self.assertEqual( self.io.getvalue(), - ('failure: %s [\n' + _remote_exception_str + ': boo qux\n]\n') - % self.test.id()) + _b(('failure: %s [\n' + _remote_exception_str + ': boo qux\n]\n') + % self.test.id())) def test_add_failure_details(self): """Test addFailure on a TestProtocolClient with details.""" @@ -1043,14 +1043,13 @@ class TestTestProtocolClient(unittest.TestCase): self.test, details=self.sample_tb_details) self.assertEqual( self.io.getvalue(), - ("failure: %s [ multipart\n" + _b(("failure: %s [ multipart\n" "Content-Type: text/plain\n" "something\n" "F\r\nserialised\nform0\r\n" "Content-Type: text/x-traceback;charset=utf8,language=python\n" - "traceback\n" - "1A\r\n" + _remote_exception_str + ": boo qux\n0\r\n" - "]\n") % self.test.id()) + "traceback\n" + _remote_exception_str_chunked + ": boo qux\n0\r\n" + "]\n") % self.test.id())) def test_add_error(self): """Test stopTest on a TestProtocolClient.""" @@ -1058,9 +1057,9 @@ class TestTestProtocolClient(unittest.TestCase): self.test, subunit.RemoteError(_u("phwoar crikey"))) self.assertEqual( self.io.getvalue(), - ('error: %s [\n' + + _b(('error: %s [\n' + _remote_exception_str + ": phwoar crikey\n" - "]\n") % self.test.id()) + "]\n") % self.test.id())) def test_add_error_details(self): """Test stopTest on a TestProtocolClient with details.""" @@ -1068,14 +1067,13 @@ class TestTestProtocolClient(unittest.TestCase): self.test, details=self.sample_tb_details) self.assertEqual( self.io.getvalue(), - ("error: %s [ multipart\n" + _b(("error: %s [ multipart\n" "Content-Type: text/plain\n" "something\n" "F\r\nserialised\nform0\r\n" "Content-Type: text/x-traceback;charset=utf8,language=python\n" - "traceback\n" - "1A\r\n" + _remote_exception_str + ": boo qux\n0\r\n" - "]\n") % self.test.id()) + "traceback\n" + _remote_exception_str_chunked + ": boo qux\n0\r\n" + "]\n") % self.test.id())) def test_add_expected_failure(self): """Test addExpectedFailure on a TestProtocolClient.""" @@ -1083,9 +1081,9 @@ class TestTestProtocolClient(unittest.TestCase): self.test, subunit.RemoteError(_u("phwoar crikey"))) self.assertEqual( self.io.getvalue(), - ('xfail: %s [\n' + + _b(('xfail: %s [\n' + _remote_exception_str + ": phwoar crikey\n" - "]\n") % self.test.id()) + "]\n") % self.test.id())) def test_add_expected_failure_details(self): """Test addExpectedFailure on a TestProtocolClient with details.""" @@ -1093,14 +1091,14 @@ class TestTestProtocolClient(unittest.TestCase): self.test, details=self.sample_tb_details) self.assertEqual( self.io.getvalue(), - ("xfail: %s [ multipart\n" + _b(("xfail: %s [ multipart\n" "Content-Type: text/plain\n" "something\n" "F\r\nserialised\nform0\r\n" "Content-Type: text/x-traceback;charset=utf8,language=python\n" - "traceback\n" - "1A\r\n"+ _remote_exception_str + ": boo qux\n0\r\n" - "]\n") % self.test.id()) + "traceback\n" + _remote_exception_str_chunked + ": boo qux\n0\r\n" + "]\n") % self.test.id())) + def test_add_skip(self): """Test addSkip on a TestProtocolClient.""" @@ -1108,64 +1106,63 @@ class TestTestProtocolClient(unittest.TestCase): self.test, "Has it really?") self.assertEqual( self.io.getvalue(), - 'skip: %s [\nHas it really?\n]\n' % self.test.id()) + _b('skip: %s [\nHas it really?\n]\n' % self.test.id())) def test_add_skip_details(self): """Test addSkip on a TestProtocolClient with details.""" details = {'reason':Content( - ContentType('text', 'plain'), lambda:['Has it really?'])} - self.protocol.addSkip( - self.test, details=details) + ContentType('text', 'plain'), lambda:[_b('Has it really?')])} + self.protocol.addSkip(self.test, details=details) self.assertEqual( self.io.getvalue(), - "skip: %s [ multipart\n" + _b("skip: %s [ multipart\n" "Content-Type: text/plain\n" "reason\n" "E\r\nHas it really?0\r\n" - "]\n" % self.test.id()) + "]\n" % self.test.id())) def test_progress_set(self): self.protocol.progress(23, subunit.PROGRESS_SET) - self.assertEqual(self.io.getvalue(), 'progress: 23\n') + self.assertEqual(self.io.getvalue(), _b('progress: 23\n')) def test_progress_neg_cur(self): self.protocol.progress(-23, subunit.PROGRESS_CUR) - self.assertEqual(self.io.getvalue(), 'progress: -23\n') + self.assertEqual(self.io.getvalue(), _b('progress: -23\n')) def test_progress_pos_cur(self): self.protocol.progress(23, subunit.PROGRESS_CUR) - self.assertEqual(self.io.getvalue(), 'progress: +23\n') + self.assertEqual(self.io.getvalue(), _b('progress: +23\n')) def test_progress_pop(self): self.protocol.progress(1234, subunit.PROGRESS_POP) - self.assertEqual(self.io.getvalue(), 'progress: pop\n') + self.assertEqual(self.io.getvalue(), _b('progress: pop\n')) def test_progress_push(self): self.protocol.progress(1234, subunit.PROGRESS_PUSH) - self.assertEqual(self.io.getvalue(), 'progress: push\n') + self.assertEqual(self.io.getvalue(), _b('progress: push\n')) def test_time(self): # Calling time() outputs a time signal immediately. self.protocol.time( datetime.datetime(2009,10,11,12,13,14,15, iso8601.Utc())) self.assertEqual( - "time: 2009-10-11 12:13:14.000015Z\n", + _b("time: 2009-10-11 12:13:14.000015Z\n"), self.io.getvalue()) def test_add_unexpected_success(self): """Test addUnexpectedSuccess on a TestProtocolClient.""" self.protocol.addUnexpectedSuccess(self.test) self.assertEqual( - self.io.getvalue(), "successful: %s\n" % self.test.id()) + self.io.getvalue(), _b("successful: %s\n" % self.test.id())) def test_add_unexpected_success_details(self): """Test addUnexpectedSuccess on a TestProtocolClient with details.""" self.protocol.addUnexpectedSuccess(self.test, details=self.sample_details) self.assertEqual( - self.io.getvalue(), "successful: %s [ multipart\n" + self.io.getvalue(), _b("successful: %s [ multipart\n" "Content-Type: text/plain\n" "something\n" - "F\r\nserialised\nform0\r\n]\n" % self.test.id()) + "F\r\nserialised\nform0\r\n]\n" % self.test.id())) def test_suite(): -- cgit v1.2.1 From 2950580814e220313b862e13ea40f3ac8163601c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 25 Apr 2011 22:32:49 +0200 Subject: Remove TagCollapsingDecator test. --- python/subunit/tests/test_test_results.py | 5 ----- 1 file changed, 5 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_test_results.py b/python/subunit/tests/test_test_results.py index 23b8b5e..94d2274 100644 --- a/python/subunit/tests/test_test_results.py +++ b/python/subunit/tests/test_test_results.py @@ -229,11 +229,6 @@ class TestTagCollapsingDecorator(TestCase): ('stopTest', test)], result._events) - def test_tags_collapsed_tests_run(self): - result = ExtendedTestResult() - tag_collapser = subunit.test_results.TagCollapsingDecorator(result) - tag_collapser.testsRun += 1 - class TestTimeCollapsingDecorator(TestCase): -- cgit v1.2.1 From 137f492db934863d0352e46aa00486b8f8d7c806 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 25 Apr 2011 22:44:33 +0200 Subject: Move read_test_filter to python/subunit. --- python/subunit/tests/test_details.py | 1 - 1 file changed, 1 deletion(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_details.py b/python/subunit/tests/test_details.py index 41c3212..2fd1a66 100644 --- a/python/subunit/tests/test_details.py +++ b/python/subunit/tests/test_details.py @@ -14,7 +14,6 @@ # limitations under that license. # -from cStringIO import StringIO import unittest import subunit.tests -- cgit v1.2.1 From 4b6abb5335d793f842abaab3121276c7737481a0 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 25 Apr 2011 22:26:51 +0100 Subject: Avoid leaking test output in TestTestProtocolServerStartTest.test_indented_test_colon_ignored --- python/subunit/tests/test_test_protocol.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index 7ec7758..d8af230 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -107,7 +107,8 @@ class TestTestProtocolServerStartTest(unittest.TestCase): def setUp(self): self.client = Python26TestResult() - self.protocol = subunit.TestProtocolServer(self.client) + self.stream = BytesIO() + self.protocol = subunit.TestProtocolServer(self.client, self.stream) def test_start_test(self): self.protocol.lineReceived(_b("test old mcdonald\n")) @@ -125,8 +126,10 @@ class TestTestProtocolServerStartTest(unittest.TestCase): [('startTest', subunit.RemotedTestCase("old mcdonald"))]) def test_indented_test_colon_ignored(self): - self.protocol.lineReceived(_b(" test: old mcdonald\n")) + ignored_line = _b(" test: old mcdonald\n") + self.protocol.lineReceived(ignored_line) self.assertEqual([], self.client._events) + self.assertEqual(self.stream.getvalue(), ignored_line) def test_start_testing_colon(self): self.protocol.lineReceived(_b("testing: old mcdonald\n")) -- cgit v1.2.1 From 5a28b540845585f07ec1f10b96305c77f63104dd Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 27 Apr 2011 02:25:24 +0100 Subject: Hack ExecTestCase and its tests to sort-of be portable fixing the remaing spew --- python/subunit/tests/sample-script.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/sample-script.py b/python/subunit/tests/sample-script.py index 0ee019a..618e495 100755 --- a/python/subunit/tests/sample-script.py +++ b/python/subunit/tests/sample-script.py @@ -1,5 +1,8 @@ #!/usr/bin/env python import sys +if sys.platform == "win32": + import msvcrt, os + msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) if len(sys.argv) == 2: # subunit.tests.test_test_protocol.TestExecTestCase.test_sample_method_args # uses this code path to be sure that the arguments were passed to -- cgit v1.2.1 From 1d41987d8fb9da38eea2e99c4f41c0840194ef0f Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 27 Apr 2011 02:27:48 +0100 Subject: Skip os.fork tests on non-posix systems, by switching to testtools testcases there --- python/subunit/tests/test_test_protocol.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index d8af230..1b1aa1d 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -21,6 +21,7 @@ import os from testtools.compat import _b, _u, BytesIO, StringIO from testtools.content import Content, TracebackContent from testtools.content_type import ContentType +from testtools.testcase import skipIf, TestCase from testtools.tests.helpers import ( Python26TestResult, Python27TestResult, @@ -922,7 +923,7 @@ class DoExecTestCase(subunit.ExecTestCase): """sample-two-script.py""" -class TestIsolatedTestCase(unittest.TestCase): +class TestIsolatedTestCase(TestCase): class SampleIsolatedTestCase(subunit.IsolatedTestCase): @@ -943,6 +944,7 @@ class TestIsolatedTestCase(unittest.TestCase): def test_construct(self): self.SampleIsolatedTestCase("test_sets_global_state") + @skipIf(os.name != "posix", "Need a posix system for forking tests") def test_run(self): result = unittest.TestResult() test = self.SampleIsolatedTestCase("test_sets_global_state") @@ -958,7 +960,7 @@ class TestIsolatedTestCase(unittest.TestCase): #test.debug() -class TestIsolatedTestSuite(unittest.TestCase): +class TestIsolatedTestSuite(TestCase): class SampleTestToIsolate(unittest.TestCase): @@ -979,6 +981,7 @@ class TestIsolatedTestSuite(unittest.TestCase): def test_construct(self): subunit.IsolatedTestSuite() + @skipIf(os.name != "posix", "Need a posix system for forking tests") def test_run(self): result = unittest.TestResult() suite = subunit.IsolatedTestSuite() -- cgit v1.2.1 From 43cc336e58f81cd4fdb1692233980110bbc80542 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 27 Apr 2011 02:32:23 +0100 Subject: Fix join_dir test by being more specific about what constitutes a match --- python/subunit/tests/test_test_protocol.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index 1b1aa1d..e0fa7ef 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -913,7 +913,8 @@ class TestExecTestCase(unittest.TestCase): def test_join_dir(self): sibling = subunit.join_dir(__file__, 'foo') - expected = '%s/foo' % (os.path.split(__file__)[0],) + filedir = os.path.abspath(os.path.dirname(__file__)) + expected = os.path.join(filedir, 'foo') self.assertEqual(sibling, expected) -- cgit v1.2.1 From 8a5727cd20a1a7ecb2050fce2977362e6b4aa068 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Mon, 2 May 2011 10:21:32 +1200 Subject: Additionally the protocol now has a keyword uxsuccess for Unexpected Success reporting. Older parsers will report tests with this status code as 'lost connection'. * The Python2.7 / testtools addUnexpectedSuccess API is now supported. This required adding a new status code to the protocol. (Robert Collins, #654474) --- python/subunit/tests/test_test_protocol.py | 126 ++++++++++++++++++++++++++++- 1 file changed, 124 insertions(+), 2 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index 7ec7758..1cf5f13 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -18,6 +18,7 @@ import datetime import unittest import os +from testtools import TestCase from testtools.compat import _b, _u, BytesIO, StringIO from testtools.content import Content, TracebackContent from testtools.content_type import ContentType @@ -366,6 +367,12 @@ class TestTestProtocolServerLostConnection(unittest.TestCase): def test_lost_connection_during_xfail_details(self): self.do_connection_lost("xfail", "[ multipart\n") + def test_lost_connection_during_uxsuccess(self): + self.do_connection_lost("uxsuccess", "[\n") + + def test_lost_connection_during_uxsuccess_details(self): + self.do_connection_lost("uxsuccess", "[ multipart\n") + class TestInTestMultipart(unittest.TestCase): @@ -607,6 +614,121 @@ class TestTestProtocolServerAddxFail(unittest.TestCase): self.xfail_quoted_bracket("xfail:", False) +class TestTestProtocolServerAddunexpectedSuccess(TestCase): + """Tests for the uxsuccess keyword.""" + + def capture_expected_failure(self, test, err): + self._events.append((test, err)) + + def setup_python26(self): + """Setup a test object ready to be xfailed and thunk to success.""" + self.client = Python26TestResult() + self.setup_protocol() + + def setup_python27(self): + """Setup a test object ready to be xfailed.""" + self.client = Python27TestResult() + self.setup_protocol() + + def setup_python_ex(self): + """Setup a test object ready to be xfailed with details.""" + self.client = ExtendedTestResult() + self.setup_protocol() + + def setup_protocol(self): + """Setup the protocol based on self.client.""" + self.protocol = subunit.TestProtocolServer(self.client) + self.protocol.lineReceived(_b("test mcdonalds farm\n")) + self.test = self.client._events[-1][-1] + + def simple_uxsuccess_keyword(self, keyword, as_fail): + self.protocol.lineReceived(_b("%s mcdonalds farm\n" % keyword)) + self.check_fail_or_uxsuccess(as_fail) + + def check_fail_or_uxsuccess(self, as_fail, error_message=None): + details = {} + if error_message is not None: + details['traceback'] = Content( + ContentType("text", "x-traceback", {'charset': 'utf8'}), + lambda:[_b(error_message)]) + if isinstance(self.client, ExtendedTestResult): + value = details + else: + value = None + if as_fail: + self.client._events[1] = self.client._events[1][:2] + # The value is generated within the extended to original decorator: + # todo use the testtools matcher to check on this. + self.assertEqual([ + ('startTest', self.test), + ('addFailure', self.test), + ('stopTest', self.test), + ], self.client._events) + elif value: + self.assertEqual([ + ('startTest', self.test), + ('addUnexpectedSuccess', self.test, value), + ('stopTest', self.test), + ], self.client._events) + else: + self.assertEqual([ + ('startTest', self.test), + ('addUnexpectedSuccess', self.test), + ('stopTest', self.test), + ], self.client._events) + + def test_simple_uxsuccess(self): + self.setup_python26() + self.simple_uxsuccess_keyword("uxsuccess", True) + self.setup_python27() + self.simple_uxsuccess_keyword("uxsuccess", False) + self.setup_python_ex() + self.simple_uxsuccess_keyword("uxsuccess", False) + + def test_simple_uxsuccess_colon(self): + self.setup_python26() + self.simple_uxsuccess_keyword("uxsuccess:", True) + self.setup_python27() + self.simple_uxsuccess_keyword("uxsuccess:", False) + self.setup_python_ex() + self.simple_uxsuccess_keyword("uxsuccess:", False) + + def test_uxsuccess_empty_message(self): + self.setup_python26() + self.empty_message(True) + self.setup_python27() + self.empty_message(False) + self.setup_python_ex() + self.empty_message(False, error_message="") + + def empty_message(self, as_fail, error_message="\n"): + self.protocol.lineReceived(_b("uxsuccess mcdonalds farm [\n")) + self.protocol.lineReceived(_b("]\n")) + self.check_fail_or_uxsuccess(as_fail, error_message) + + def uxsuccess_quoted_bracket(self, keyword, as_fail): + self.protocol.lineReceived(_b("%s mcdonalds farm [\n" % keyword)) + self.protocol.lineReceived(_b(" ]\n")) + self.protocol.lineReceived(_b("]\n")) + self.check_fail_or_uxsuccess(as_fail, "]\n") + + def test_uxsuccess_quoted_bracket(self): + self.setup_python26() + self.uxsuccess_quoted_bracket("uxsuccess", True) + self.setup_python27() + self.uxsuccess_quoted_bracket("uxsuccess", False) + self.setup_python_ex() + self.uxsuccess_quoted_bracket("uxsuccess", False) + + def test_uxsuccess_colon_quoted_bracket(self): + self.setup_python26() + self.uxsuccess_quoted_bracket("uxsuccess:", True) + self.setup_python27() + self.uxsuccess_quoted_bracket("uxsuccess:", False) + self.setup_python_ex() + self.uxsuccess_quoted_bracket("uxsuccess:", False) + + class TestTestProtocolServerAddSkip(unittest.TestCase): """Tests for the skip keyword. @@ -1153,13 +1275,13 @@ class TestTestProtocolClient(unittest.TestCase): """Test addUnexpectedSuccess on a TestProtocolClient.""" self.protocol.addUnexpectedSuccess(self.test) self.assertEqual( - self.io.getvalue(), _b("successful: %s\n" % self.test.id())) + self.io.getvalue(), _b("uxsuccess: %s\n" % self.test.id())) def test_add_unexpected_success_details(self): """Test addUnexpectedSuccess on a TestProtocolClient with details.""" self.protocol.addUnexpectedSuccess(self.test, details=self.sample_details) self.assertEqual( - self.io.getvalue(), _b("successful: %s [ multipart\n" + self.io.getvalue(), _b("uxsuccess: %s [ multipart\n" "Content-Type: text/plain\n" "something\n" "F\r\nserialised\nform0\r\n]\n" % self.test.id())) -- cgit v1.2.1 From d7f31020565d999ac02e460401068d3f7c70568d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 9 May 2011 23:00:42 +0200 Subject: Add test to make sure addSkip is preserved. --- python/subunit/tests/test_subunit_filter.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py index 87d4209..0675484 100644 --- a/python/subunit/tests/test_subunit_filter.py +++ b/python/subunit/tests/test_subunit_filter.py @@ -187,6 +187,20 @@ xfail todo ('stopTest', foo), ('time', date_c)], result._events) + def test_skip_preserved(self): + subunit_stream = _b('\n'.join([ + "test: foo", + "skip: foo", + ""])) + result = ExtendedTestResult() + result_filter = TestResultFilter(result) + self.run_tests(result_filter, subunit_stream) + foo = subunit.RemotedTestCase('foo') + self.assertEquals( + [('startTest', foo), + ('addSkip', foo, {}), + ('stopTest', foo), ], result._events) + def test_suite(): loader = subunit.tests.TestUtil.TestLoader() -- cgit v1.2.1 From 7384e95b6e49ea544739abfdd52e846eab292f69 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 13 Oct 2011 02:16:57 +0200 Subject: Newer versions of testtools have {Python26,Python27,Extended}TestResult in testtools.testresult.doubles. --- python/subunit/tests/test_test_protocol.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index 03d921a..c93aabd 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -22,11 +22,18 @@ from testtools import skipIf, TestCase from testtools.compat import _b, _u, BytesIO, StringIO from testtools.content import Content, TracebackContent from testtools.content_type import ContentType -from testtools.tests.helpers import ( - Python26TestResult, - Python27TestResult, - ExtendedTestResult, - ) +try: + from testtools.testresult.doubles import ( + Python26TestResult, + Python27TestResult, + ExtendedTestResult, + ) +except ImportError: + from testtools.tests.helpers import ( + Python26TestResult, + Python27TestResult, + ExtendedTestResult, + ) import subunit from subunit import _remote_exception_str, _remote_exception_str_chunked -- cgit v1.2.1 From 5c3f13ee9f2d195b605a1b3522fb00e8d5e79786 Mon Sep 17 00:00:00 2001 From: James Westby Date: Tue, 1 Nov 2011 11:59:58 -0400 Subject: Have the output of subunit.run include timing information. --- python/subunit/tests/__init__.py | 2 ++ python/subunit/tests/test_run.py | 53 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 python/subunit/tests/test_run.py (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/__init__.py b/python/subunit/tests/__init__.py index a78cec8..e0e1eb1 100644 --- a/python/subunit/tests/__init__.py +++ b/python/subunit/tests/__init__.py @@ -19,6 +19,7 @@ from subunit.tests import ( test_chunked, test_details, test_progress_model, + test_run, test_subunit_filter, test_subunit_stats, test_subunit_tags, @@ -38,4 +39,5 @@ def test_suite(): result.addTest(test_subunit_filter.test_suite()) result.addTest(test_subunit_tags.test_suite()) result.addTest(test_subunit_stats.test_suite()) + result.addTest(test_run.test_suite()) return result diff --git a/python/subunit/tests/test_run.py b/python/subunit/tests/test_run.py new file mode 100644 index 0000000..e695703 --- /dev/null +++ b/python/subunit/tests/test_run.py @@ -0,0 +1,53 @@ +# +# subunit: extensions to python unittest to get test results from subprocesses. +# Copyright (C) 2005 Robert Collins +# Copyright (C) 2011 Martin Pool +# +# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause +# license at the users choice. A copy of both licenses are available in the +# project source as Apache-2.0 and BSD. You may not use this file except in +# compliance with one of these two licences. +# +# Unless required by applicable law or agreed to in writing, software +# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# license you chose for the specific language governing permissions and +# limitations under that license. +# + +from cStringIO import StringIO +import unittest + +from testtools import PlaceHolder + +import subunit +from subunit.run import SubunitTestRunner + + +def test_suite(): + loader = subunit.tests.TestUtil.TestLoader() + result = loader.loadTestsFromName(__name__) + return result + + +class TimeCollectingTestResult(unittest.TestResult): + + def __init__(self, *args, **kwargs): + super(TimeCollectingTestResult, self).__init__(*args, **kwargs) + self.time_called = [] + + def time(self, a_time): + self.time_called.append(a_time) + + +class TestSubunitTestRunner(unittest.TestCase): + + def test_includes_timing_output(self): + io = StringIO() + runner = SubunitTestRunner(stream=io) + test = PlaceHolder('name') + runner.run(test) + client = TimeCollectingTestResult() + io.seek(0) + subunit.TestProtocolServer(client).readFrom(io) + self.assertTrue(len(client.time_called) > 0) -- cgit v1.2.1 From 927d6ffbfec0ea269c9dd477d3053b6ff0e73600 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Tue, 1 Nov 2011 12:40:48 -0400 Subject: Copyright update. --- python/subunit/tests/test_run.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_run.py b/python/subunit/tests/test_run.py index e695703..5a96bcf 100644 --- a/python/subunit/tests/test_run.py +++ b/python/subunit/tests/test_run.py @@ -1,7 +1,6 @@ # # subunit: extensions to python unittest to get test results from subprocesses. -# Copyright (C) 2005 Robert Collins -# Copyright (C) 2011 Martin Pool +# Copyright (C) 2011 Robert Collins # # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause # license at the users choice. A copy of both licenses are available in the -- cgit v1.2.1 From ec629cf047c0f4e1d2d51d30a3d72e5437017936 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Wed, 11 Jan 2012 18:32:22 +1300 Subject: Handle latest testtools changes. --- python/subunit/tests/test_test_protocol.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index c93aabd..019c080 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -102,9 +102,9 @@ class TestTestProtocolServerPipe(unittest.TestCase): [(an_error, _remote_exception_str + '\n')]) self.assertEqual( client.failures, - [(bing, _remote_exception_str + ": Text attachment: traceback\n" - "------------\nfoo.c:53:ERROR invalid state\n" - "------------\n\n")]) + [(bing, _remote_exception_str + + ": foo.c:53:ERROR invalid state\n" + "\n")]) self.assertEqual(client.testsRun, 3) def test_non_test_characters_forwarded_immediately(self): @@ -559,9 +559,9 @@ class TestTestProtocolServerAddxFail(unittest.TestCase): value = details else: if error_message is not None: - value = subunit.RemoteError(_u("Text attachment: traceback\n" - "------------\n") + _u(error_message) + - _u("------------\n")) + if not len(error_message.strip()): + error_message = _u("Empty attachments:\n traceback\n") + value = subunit.RemoteError(_u(error_message)) else: value = subunit.RemoteError() self.assertEqual([ -- cgit v1.2.1 From 25581a35bb8b7468dd0e3ada1f5b20555e8eab30 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Wed, 11 Jan 2012 18:42:53 +1300 Subject: Tag support has been implemented for TestProtocolClient. (Robert Collins, #518016) --- python/subunit/tests/test_test_protocol.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'python/subunit/tests') diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index 019c080..091b370 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -1299,6 +1299,22 @@ class TestTestProtocolClient(unittest.TestCase): "something\n" "F\r\nserialised\nform0\r\n]\n" % self.test.id())) + def test_tags_empty(self): + self.protocol.tags(set(), set()) + self.assertEqual(_b(""), self.io.getvalue()) + + def test_tags_add(self): + self.protocol.tags(set(['foo']), set()) + self.assertEqual(_b("tags: foo\n"), self.io.getvalue()) + + def test_tags_both(self): + self.protocol.tags(set(['quux']), set(['bar'])) + self.assertEqual(_b("tags: quux -bar\n"), self.io.getvalue()) + + def test_tags_gone(self): + self.protocol.tags(set(), set(['bar'])) + self.assertEqual(_b("tags: -bar\n"), self.io.getvalue()) + def test_suite(): loader = subunit.tests.TestUtil.TestLoader() -- cgit v1.2.1