diff options
| author | Jelmer Vernooij <jelmer@jelmer.uk> | 2018-08-26 13:16:56 +0100 |
|---|---|---|
| committer | Jelmer Vernooij <jelmer@jelmer.uk> | 2018-08-26 14:02:34 +0100 |
| commit | a530e10e6f25195f2512826407fad2a81a672756 (patch) | |
| tree | 3457c650b1e947f93e7e8c5e25a9005fc0282504 /testrepository/tests | |
| parent | 2bde14731a681cf4a97da88152883c165b286c3e (diff) | |
| download | testrepository-git-v2-only.tar.gz | |
Drop support for pre-0.0.11 versions of subunit.v2-only
Diffstat (limited to 'testrepository/tests')
| -rw-r--r-- | testrepository/tests/commands/test_list_tests.py | 28 | ||||
| -rw-r--r-- | testrepository/tests/commands/test_load.py | 111 | ||||
| -rw-r--r-- | testrepository/tests/commands/test_run.py | 70 | ||||
| -rw-r--r-- | testrepository/tests/test_testcommand.py | 41 |
4 files changed, 92 insertions, 158 deletions
diff --git a/testrepository/tests/commands/test_list_tests.py b/testrepository/tests/commands/test_list_tests.py index eda9efa..76b9337 100644 --- a/testrepository/tests/commands/test_list_tests.py +++ b/testrepository/tests/commands/test_list_tests.py @@ -18,9 +18,7 @@ from io import BytesIO import os.path from subprocess import PIPE -from extras import try_import import subunit -v2_avail = try_import('subunit.ByteStreamToStreamResult') from testtools.compat import _b from testtools.matchers import MatchesException @@ -75,14 +73,11 @@ class TestCommand(ResourcedTestCase): def test_calls_list_tests(self): ui, cmd = self.get_test_ui_and_cmd(args=('--', 'bar', 'quux')) cmd.repository_factory = memory.RepositoryFactory() - if v2_avail: - buffer = BytesIO() - stream = subunit.StreamResultToBytes(buffer) - stream.status(test_id='returned', test_status='exists') - stream.status(test_id='values', test_status='exists') - subunit_bytes = buffer.getvalue() - else: - subunit_bytes = _b('returned\n\nvalues\n') + buffer = BytesIO() + stream = subunit.StreamResultToBytes(buffer) + stream.status(test_id='returned', test_status='exists') + stream.status(test_id='values', test_status='exists') + subunit_bytes = buffer.getvalue() ui.proc_outputs = [subunit_bytes] self.setup_repo(cmd, ui) self.set_config( @@ -103,14 +98,11 @@ class TestCommand(ResourcedTestCase): ui, cmd = self.get_test_ui_and_cmd( args=('returned', '--', 'bar', 'quux')) cmd.repository_factory = memory.RepositoryFactory() - if v2_avail: - buffer = BytesIO() - stream = subunit.StreamResultToBytes(buffer) - stream.status(test_id='returned', test_status='exists') - stream.status(test_id='values', test_status='exists') - subunit_bytes = buffer.getvalue() - else: - subunit_bytes = _b('returned\nvalues\n') + buffer = BytesIO() + stream = subunit.StreamResultToBytes(buffer) + stream.status(test_id='returned', test_status='exists') + stream.status(test_id='values', test_status='exists') + subunit_bytes = buffer.getvalue() ui.proc_outputs = [subunit_bytes] self.setup_repo(cmd, ui) self.set_config( diff --git a/testrepository/tests/commands/test_load.py b/testrepository/tests/commands/test_load.py index a0c2947..89a0589 100644 --- a/testrepository/tests/commands/test_load.py +++ b/testrepository/tests/commands/test_load.py @@ -18,8 +18,6 @@ from datetime import datetime, timedelta from io import BytesIO from tempfile import NamedTemporaryFile -from extras import try_import -v2_avail = try_import('subunit.ByteStreamToStreamResult') import subunit from subunit import iso8601 @@ -115,14 +113,11 @@ class TestCommandLoad(ResourcedTestCase): self.assertEqual(0, cmd.execute()) def test_load_returns_1_on_failed_stream(self): - if v2_avail: - buffer = BytesIO() - stream = subunit.StreamResultToBytes(buffer) - stream.status(test_id='foo', test_status='inprogress') - stream.status(test_id='foo', test_status='fail') - subunit_bytes = buffer.getvalue() - else: - subunit_bytes = _b('test: foo\nfailure: foo\n') + buffer = BytesIO() + stream = subunit.StreamResultToBytes(buffer) + stream.status(test_id='foo', test_status='inprogress') + stream.status(test_id='foo', test_status='fail') + subunit_bytes = buffer.getvalue() ui = UI([('subunit', subunit_bytes)]) cmd = load.load(ui) ui.set_command(cmd) @@ -131,14 +126,11 @@ class TestCommandLoad(ResourcedTestCase): self.assertEqual(1, cmd.execute()) def test_load_new_shows_test_failures(self): - if v2_avail: - buffer = BytesIO() - stream = subunit.StreamResultToBytes(buffer) - stream.status(test_id='foo', test_status='inprogress') - stream.status(test_id='foo', test_status='fail') - subunit_bytes = buffer.getvalue() - else: - subunit_bytes = b'test: foo\nfailure: foo\n' + buffer = BytesIO() + stream = subunit.StreamResultToBytes(buffer) + stream.status(test_id='foo', test_status='inprogress') + stream.status(test_id='foo', test_status='fail') + subunit_bytes = buffer.getvalue() ui = UI([('subunit', subunit_bytes)]) cmd = load.load(ui) ui.set_command(cmd) @@ -151,16 +143,13 @@ class TestCommandLoad(ResourcedTestCase): ui.outputs[1:]) def test_load_new_shows_test_failure_details(self): - if v2_avail: - buffer = BytesIO() - stream = subunit.StreamResultToBytes(buffer) - stream.status(test_id='foo', test_status='inprogress') - stream.status(test_id='foo', test_status='fail', - file_name="traceback", mime_type='text/plain;charset=utf8', - file_bytes=b'arg\n') - subunit_bytes = buffer.getvalue() - else: - subunit_bytes = b'test: foo\nfailure: foo [\narg\n]\n' + buffer = BytesIO() + stream = subunit.StreamResultToBytes(buffer) + stream.status(test_id='foo', test_status='inprogress') + stream.status(test_id='foo', test_status='fail', + file_name="traceback", mime_type='text/plain;charset=utf8', + file_bytes=b'arg\n') + subunit_bytes = buffer.getvalue() ui = UI([('subunit', subunit_bytes)]) cmd = load.load(ui) ui.set_command(cmd) @@ -183,14 +172,11 @@ class TestCommandLoad(ResourcedTestCase): self.assertEqual(1, len(result.errors)) def test_load_new_shows_test_skips(self): - if v2_avail: - buffer = BytesIO() - stream = subunit.StreamResultToBytes(buffer) - stream.status(test_id='foo', test_status='inprogress') - stream.status(test_id='foo', test_status='skip') - subunit_bytes = buffer.getvalue() - else: - subunit_bytes = b'test: foo\nskip: foo\n' + buffer = BytesIO() + stream = subunit.StreamResultToBytes(buffer) + stream.status(test_id='foo', test_status='inprogress') + stream.status(test_id='foo', test_status='skip') + subunit_bytes = buffer.getvalue() ui = UI([('subunit', subunit_bytes)]) cmd = load.load(ui) ui.set_command(cmd) @@ -251,20 +237,13 @@ class TestCommandLoad(ResourcedTestCase): cmd.repository_factory.repos[ui.here].get_test_run(0)._partial) def test_load_timed_run(self): - if v2_avail: - buffer = BytesIO() - stream = subunit.StreamResultToBytes(buffer) - time = datetime(2011, 1, 1, 0, 0, 1, tzinfo=iso8601.Utc()) - stream.status(test_id='foo', test_status='inprogress', timestamp=time) - stream.status(test_id='foo', test_status='success', - timestamp=time+timedelta(seconds=2)) - timed_bytes = buffer.getvalue() - else: - timed_bytes = _b('time: 2011-01-01 00:00:01.000000Z\n' - 'test: foo\n' - 'time: 2011-01-01 00:00:03.000000Z\n' - 'success: foo\n' - 'time: 2011-01-01 00:00:06.000000Z\n') + buffer = BytesIO() + stream = subunit.StreamResultToBytes(buffer) + time = datetime(2011, 1, 1, 0, 0, 1, tzinfo=iso8601.Utc()) + stream.status(test_id='foo', test_status='inprogress', timestamp=time) + stream.status(test_id='foo', test_status='success', + timestamp=time+timedelta(seconds=2)) + timed_bytes = buffer.getvalue() ui = UI( [('subunit', timed_bytes)]) cmd = load.load(ui) @@ -284,27 +263,17 @@ class TestCommandLoad(ResourcedTestCase): # If there's a previous run in the database, then show information # about the high level differences in the test run: how many more # tests, how many more failures, how much longer it takes. - if v2_avail: - buffer = BytesIO() - stream = subunit.StreamResultToBytes(buffer) - time = datetime(2011, 1, 2, 0, 0, 1, tzinfo=iso8601.Utc()) - stream.status(test_id='foo', test_status='inprogress', timestamp=time) - stream.status(test_id='foo', test_status='fail', - timestamp=time+timedelta(seconds=2)) - stream.status(test_id='bar', test_status='inprogress', - timestamp=time+timedelta(seconds=4)) - stream.status(test_id='bar', test_status='fail', - timestamp=time+timedelta(seconds=6)) - timed_bytes = buffer.getvalue() - else: - timed_bytes = _b('time: 2011-01-02 00:00:01.000000Z\n' - 'test: foo\n' - 'time: 2011-01-02 00:00:03.000000Z\n' - 'error: foo\n' - 'time: 2011-01-02 00:00:05.000000Z\n' - 'test: bar\n' - 'time: 2011-01-02 00:00:07.000000Z\n' - 'error: bar\n') + buffer = BytesIO() + stream = subunit.StreamResultToBytes(buffer) + time = datetime(2011, 1, 2, 0, 0, 1, tzinfo=iso8601.Utc()) + stream.status(test_id='foo', test_status='inprogress', timestamp=time) + stream.status(test_id='foo', test_status='fail', + timestamp=time+timedelta(seconds=2)) + stream.status(test_id='bar', test_status='inprogress', + timestamp=time+timedelta(seconds=4)) + stream.status(test_id='bar', test_status='fail', + timestamp=time+timedelta(seconds=6)) + timed_bytes = buffer.getvalue() ui = UI( [('subunit', timed_bytes)]) cmd = load.load(ui) diff --git a/testrepository/tests/commands/test_run.py b/testrepository/tests/commands/test_run.py index a6d9ce1..ed671d1 100644 --- a/testrepository/tests/commands/test_run.py +++ b/testrepository/tests/commands/test_run.py @@ -19,13 +19,11 @@ import os.path from subprocess import PIPE import tempfile -from extras import try_import from fixtures import ( Fixture, MonkeyPatch, ) import subunit -v2_avail = try_import('subunit.ByteStreamToStreamResult') from subunit import RemotedTestCase from testscenarios.scenarios import multiply_scenarios from testtools.compat import _b @@ -298,14 +296,11 @@ class TestCommand(ResourcedTestCase): cmd.repository_factory.repos[ui.here].get_test_run(1)._partial) def test_load_failure_exposed(self): - if v2_avail: - buffer = BytesIO() - stream = subunit.StreamResultToBytes(buffer) - stream.status(test_id='foo', test_status='inprogress') - stream.status(test_id='foo', test_status='fail') - subunit_bytes = buffer.getvalue() - else: - subunit_bytes = b'test: foo\nfailure: foo\n' + buffer = BytesIO() + stream = subunit.StreamResultToBytes(buffer) + stream.status(test_id='foo', test_status='inprogress') + stream.status(test_id='foo', test_status='fail') + subunit_bytes = buffer.getvalue() ui, cmd = self.get_test_ui_and_cmd(options=[('quiet', True),], proc_outputs=[subunit_bytes]) cmd.repository_factory = memory.RepositoryFactory() @@ -316,14 +311,11 @@ class TestCommand(ResourcedTestCase): self.assertEqual(1, result) def test_process_exit_code_nonzero_causes_synthetic_error_test(self): - if v2_avail: - buffer = BytesIO() - stream = subunit.StreamResultToBytes(buffer) - stream.status(test_id='foo', test_status='inprogress') - stream.status(test_id='foo', test_status='success') - subunit_bytes = buffer.getvalue() - else: - subunit_bytes = b'test: foo\nsuccess: foo\n' + buffer = BytesIO() + stream = subunit.StreamResultToBytes(buffer) + stream.status(test_id='foo', test_status='inprogress') + stream.status(test_id='foo', test_status='success') + subunit_bytes = buffer.getvalue() ui, cmd = self.get_test_ui_and_cmd(options=[('quiet', True),], proc_outputs=[subunit_bytes], proc_results=[2]) @@ -390,20 +382,16 @@ class TestCommand(ResourcedTestCase): def test_until_failure(self): ui, cmd = self.get_test_ui_and_cmd(options=[('until_failure', True)]) - if v2_avail: - buffer = BytesIO() - stream = subunit.StreamResultToBytes(buffer) - stream.status(test_id='foo', test_status='inprogress') - stream.status(test_id='foo', test_status='success') - subunit_bytes1 = buffer.getvalue() - buffer.seek(0) - buffer.truncate() - stream.status(test_id='foo', test_status='inprogress') - stream.status(test_id='foo', test_status='fail') - subunit_bytes2 = buffer.getvalue() - else: - subunit_bytes1 = b'test: foo\nsuccess: foo\n' - subunit_bytes2 = b'test: foo\nfailure: foo\n' + buffer = BytesIO() + stream = subunit.StreamResultToBytes(buffer) + stream.status(test_id='foo', test_status='inprogress') + stream.status(test_id='foo', test_status='success') + subunit_bytes1 = buffer.getvalue() + buffer.seek(0) + buffer.truncate() + stream.status(test_id='foo', test_status='inprogress') + stream.status(test_id='foo', test_status='fail') + subunit_bytes2 = buffer.getvalue() ui.proc_outputs = [ subunit_bytes1, # stream one, works subunit_bytes2, # stream two, fails @@ -527,15 +515,11 @@ class TestReturnCodeToSubunit(ResourcedTestCase): proc.returncode = 1 stream = run.ReturnCodeToSubunit(proc) content = accumulate(stream, self.reader) - if v2_avail: - buffer = BytesIO() - buffer.write(b'foo\nbar\n') - stream = subunit.StreamResultToBytes(buffer) - stream.status(test_id='process-returncode', test_status='fail', - file_name='traceback', mime_type='text/plain;charset=utf8', - file_bytes=b'returncode 1') - expected_content = buffer.getvalue() - else: - expected_content = _b('foo\nbar\ntest: process-returncode\n' - 'failure: process-returncode [\n returncode 1\n]\n') + buffer = BytesIO() + buffer.write(b'foo\nbar\n') + stream = subunit.StreamResultToBytes(buffer) + stream.status(test_id='process-returncode', test_status='fail', + file_name='traceback', mime_type='text/plain;charset=utf8', + file_bytes=b'returncode 1') + expected_content = buffer.getvalue() self.assertEqual(expected_content, content) diff --git a/testrepository/tests/test_testcommand.py b/testrepository/tests/test_testcommand.py index 3259e68..527e615 100644 --- a/testrepository/tests/test_testcommand.py +++ b/testrepository/tests/test_testcommand.py @@ -19,9 +19,7 @@ import os.path import optparse import re -from extras import try_import import subunit -v2_avail = try_import('subunit.ByteStreamToStreamResult') from testtools.compat import _b from testtools.matchers import ( Equals, @@ -185,14 +183,11 @@ class TestTestCommand(ResourcedTestCase): def test_get_run_command_default_and_list_expands(self): ui, command = self.get_test_ui_and_cmd() - if v2_avail: - buffer = BytesIO() - stream = subunit.StreamResultToBytes(buffer) - stream.status(test_id='returned', test_status='exists') - stream.status(test_id='ids', test_status='exists') - subunit_bytes = buffer.getvalue() - else: - subunit_bytes = _b('returned\nids\n') + buffer = BytesIO() + stream = subunit.StreamResultToBytes(buffer) + stream.status(test_id='returned', test_status='exists') + stream.status(test_id='ids', test_status='exists') + subunit_bytes = buffer.getvalue() ui.proc_outputs = [subunit_bytes] ui.options = optparse.Values() ui.options.parallel = True @@ -305,14 +300,11 @@ class TestTestCommand(ResourcedTestCase): self.assertEqual(expected_cmd, fixture.list_cmd) def test_list_tests_parsing(self): - if v2_avail: - buffer = BytesIO() - stream = subunit.StreamResultToBytes(buffer) - stream.status(test_id='returned', test_status='exists') - stream.status(test_id='ids', test_status='exists') - subunit_bytes = buffer.getvalue() - else: - subunit_bytes = _b('returned\nids\n') + buffer = BytesIO() + stream = subunit.StreamResultToBytes(buffer) + stream.status(test_id='returned', test_status='exists') + stream.status(test_id='ids', test_status='exists') + subunit_bytes = buffer.getvalue() ui, command = self.get_test_ui_and_cmd() ui.proc_outputs = [subunit_bytes] self.set_config( @@ -548,14 +540,11 @@ class TestTestCommand(ResourcedTestCase): self.assertEqual([], ui.outputs) def test_filter_tests_by_regex_only(self): - if v2_avail: - buffer = BytesIO() - stream = subunit.StreamResultToBytes(buffer) - stream.status(test_id='returned', test_status='exists') - stream.status(test_id='ids', test_status='exists') - subunit_bytes = buffer.getvalue() - else: - subunit_bytes = _b('returned\nids\n') + buffer = BytesIO() + stream = subunit.StreamResultToBytes(buffer) + stream.status(test_id='returned', test_status='exists') + stream.status(test_id='ids', test_status='exists') + subunit_bytes = buffer.getvalue() ui, command = self.get_test_ui_and_cmd() ui.proc_outputs = [subunit_bytes] self.set_config( |
