diff options
author | Robert Collins <robertc@robertcollins.net> | 2012-12-06 18:12:30 +1300 |
---|---|---|
committer | Robert Collins <robertc@robertcollins.net> | 2012-12-06 18:12:30 +1300 |
commit | 0b2787c76e14cef0fbc1ec380897396f14ac5771 (patch) | |
tree | f4e0686f73ba91748750ca41aa8ec9f450100107 /testrepository/tests/commands | |
parent | 1aa73ebfa32b9a3e0001f967d7d4e49d7cc01803 (diff) | |
download | testrepository-0b2787c76e14cef0fbc1ec380897396f14ac5771.tar.gz |
* ``testr last`` now supports ``--subunit`` and when passed will output
the stored subunit stream. Note that the exit code is always 0 when this
is done (unless an exception occurs reading the stream) - subunit consumers
should parse the subunit to determine success/failure. (Robert Collins)
Diffstat (limited to 'testrepository/tests/commands')
-rw-r--r-- | testrepository/tests/commands/test_last.py | 61 |
1 files changed, 45 insertions, 16 deletions
diff --git a/testrepository/tests/commands/test_last.py b/testrepository/tests/commands/test_last.py index 4482349..ff2450c 100644 --- a/testrepository/tests/commands/test_last.py +++ b/testrepository/tests/commands/test_last.py @@ -15,6 +15,7 @@ """Tests for the last command.""" import testtools +from testtools.matchers import Equals from testrepository.commands import last from testrepository.ui.model import UI @@ -28,8 +29,8 @@ from testrepository.tests import ( class TestCommand(ResourcedTestCase): - def get_test_ui_and_cmd(self,args=()): - ui = UI(args=args) + def get_test_ui_and_cmd(self, args=(), options=()): + ui = UI(args=args, options=options) cmd = last.last(ui) ui.set_command(cmd) return ui, cmd @@ -65,23 +66,24 @@ class TestCommand(ResourcedTestCase): self.assertEqual(1, len(result.failures)) self.assertEqual(2, result.testsRun) + def _add_run(self, repo): + inserter = repo.get_inserter() + inserter.startTestRun() + class Cases(ResourcedTestCase): + def failing(self): + self.fail('foo') + def ok(self): + pass + Cases('failing').run(inserter) + Cases('ok').run(inserter) + return inserter.stopTestRun() + def test_shows_last_run(self): ui, cmd = self.get_test_ui_and_cmd() cmd.repository_factory = memory.RepositoryFactory() repo = cmd.repository_factory.initialise(ui.here) - def add_run(): - inserter = repo.get_inserter() - inserter.startTestRun() - class Cases(ResourcedTestCase): - def failing(self): - self.fail('foo') - def ok(self): - pass - Cases('failing').run(inserter) - Cases('ok').run(inserter) - return inserter.stopTestRun() - add_run() - id = add_run() + self._add_run(repo) + id = self._add_run(repo) self.assertEqual(1, cmd.execute()) # We should have seen test outputs (of the failure) and summary data. self.assertEqual([ @@ -105,9 +107,36 @@ class TestCommand(ResourcedTestCase): repo = cmd.repository_factory.initialise(ui.here) inserter = repo.get_inserter() inserter.startTestRun() - id = inserter.stopTestRun() + inserter.stopTestRun() cmd.command_factory = StubTestCommand() cmd.execute() self.assertEqual( [('startTestRun',), ('stopTestRun',)], cmd.command_factory.results[0]._events) + + def test_shows_subunit_stream(self): + ui, cmd = self.get_test_ui_and_cmd(options=[('subunit', True)]) + cmd.repository_factory = memory.RepositoryFactory() + repo = cmd.repository_factory.initialise(ui.here) + self._add_run(repo) + self.assertEqual(0, cmd.execute()) + # We should have seen test outputs (of the failure) and summary data. + self.assertEqual([ + ('stream', Wildcard), + ], ui.outputs) + self.assertThat(ui.outputs[0][1], Equals("""\ +test: testrepository.tests.commands.test_last.Cases.failing +failure: testrepository.tests.commands.test_last.Cases.failing [ multipart +Content-Type: text/x-traceback;charset=utf8,language=python +traceback +95\r +Traceback (most recent call last): + File "testrepository/tests/commands/test_last.py", line 74, in failing + self.fail('foo') +AssertionError: foo +0\r +] +test: testrepository.tests.commands.test_last.Cases.ok +successful: testrepository.tests.commands.test_last.Cases.ok [ multipart +] +""")) |