From 55af015d80cb2924ea2d59561ca3843dcc844345 Mon Sep 17 00:00:00 2001 From: Thomi Richards Date: Wed, 20 Nov 2013 14:28:49 +1300 Subject: code cleanup, added a few more tests for the --file-name option. --- python/subunit/_output.py | 9 +++++---- python/subunit/tests/test_output_filter.py | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) (limited to 'python/subunit') diff --git a/python/subunit/_output.py b/python/subunit/_output.py index 08ed3fc..12479e8 100644 --- a/python/subunit/_output.py +++ b/python/subunit/_output.py @@ -40,7 +40,7 @@ def parse_arguments(args=None, ParserClass=ArgumentParser): """ parser = ParserClass( prog='subunit-output', - description="A tool to generate a subunit result byte-stream", + description="A tool to generate a subunit v2 result byte-stream", ) status_commands = parser.add_argument_group( @@ -48,9 +48,10 @@ def parse_arguments(args=None, ParserClass=ArgumentParser): "These options report the status of a test. TEST_ID must be a string " "that uniquely identifies the test." ) - final_actions = 'success fail skip xfail uxsuccess'.split() - for action in "inprogress success fail skip exists xfail uxsuccess".split(): - final_text = "This is a final state: No more status reports may "\ + final_actions = 'exists fail skip success xfail uxsuccess'.split() + all_actions = final_actions + ['inprogress'] + for action in all_actions: + final_text = " This is a final state: No more status reports may "\ "be generated for this test id after this one." status_commands.add_argument( diff --git a/python/subunit/tests/test_output_filter.py b/python/subunit/tests/test_output_filter.py index 15dce81..ede32dc 100644 --- a/python/subunit/tests/test_output_filter.py +++ b/python/subunit/tests/test_output_filter.py @@ -90,6 +90,13 @@ class TestStatusArgParserTests(WithScenarios, TestCase): ) self.assertThat(args.mimetype, Equals("text/plain")) + def test_all_commands_accept_file_name_argument(self): + with NamedTemporaryFile() as tmp_file: + args = safe_parse_arguments( + args=[self.option, 'foo', '--attach-file', tmp_file.name, '--file-name', "foo"] + ) + self.assertThat(args.file_name, Equals("foo")) + def test_all_commands_accept_tags_argument(self): args = safe_parse_arguments( args=[self.option, 'foo', '--tags', "foo,bar,baz"] @@ -104,6 +111,19 @@ class TestStatusArgParserTests(WithScenarios, TestCase): self.assertThat(args.attach_file.read(), Equals("Hello")) + def test_attach_file_with_hyphen_sets_filename_to_stdin(self): + args = safe_parse_arguments( + args=[self.option, "foo", "--attach-file", "-"] + ) + + self.assertThat(args.file_name, Equals("stdin")) + + def test_can_override_stdin_filename(self): + args = safe_parse_arguments( + args=[self.option, "foo", "--attach-file", "-", '--file-name', 'foo'] + ) + + self.assertThat(args.file_name, Equals("foo")) class ArgParserTests(TestCase): -- cgit v1.2.1