From 8ee031da94894c8249ba79a5f20442def5944699 Mon Sep 17 00:00:00 2001 From: Thomi Richards Date: Mon, 25 Nov 2013 18:30:14 +1300 Subject: Add tests around reading binary files, empty files, and stdin. --- python/subunit/tests/test_output_filter.py | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'python') diff --git a/python/subunit/tests/test_output_filter.py b/python/subunit/tests/test_output_filter.py index a31ae2b..758110e 100644 --- a/python/subunit/tests/test_output_filter.py +++ b/python/subunit/tests/test_output_filter.py @@ -288,6 +288,39 @@ class StatusStreamResultTests(WithScenarios, TestCase): ]) ) + def test_can_read_binary_files(self): + with temp_file_contents(b"\xDE\xAD\xBE\xEF") as f: + result = get_result_for([self.option, self.test_id, '--attach-file', f.name]) + + self.assertThat( + result._events, + MatchesListwise([ + MatchesStatusCall(file_bytes=b"\xDE\xAD\xBE\xEF", eof=True), + ]) + ) + + def test_can_read_empty_files(self): + with temp_file_contents(b"") as f: + result = get_result_for([self.option, self.test_id, '--attach-file', f.name]) + + self.assertThat( + result._events, + MatchesListwise([ + MatchesStatusCall(file_bytes=b"", file_name=f.name, eof=True), + ]) + ) + + def test_can_read_stdin(self): + self.patch(_o.sys, 'stdin', BytesIO(b"\xFE\xED\xFA\xCE")) + result = get_result_for([self.option, self.test_id, '--attach-file', '-']) + + self.assertThat( + result._events, + MatchesListwise([ + MatchesStatusCall(file_bytes=b"\xFE\xED\xFA\xCE", file_name='stdin', eof=True), + ]) + ) + def test_file_is_sent_with_test_id(self): with temp_file_contents(b"Hello") as f: result = get_result_for([self.option, self.test_id, '--attach-file', f.name]) -- cgit v1.2.1