def test_non_subunit_disabled_raises(self): source = BytesIO(b"foo\nbar\n") result = doubles.StreamResult() case = v2.ByteStreamToStreamResult(source) e = self.assertRaises(Exception, case.run, result) # noqa self.assertEqual(b'f', e.args[1]) self.assertEqual(b'oo\nbar\n', source.read()) self.assertEqual([], result._events)
def test_trivial_enumeration(self): source = BytesIO(CONSTANT_ENUM) result = doubles.StreamResult() v2.ByteStreamToStreamResult(source, non_subunit_name="stdout").run(result) self.assertEqual(b'', source.read()) self.assertEqual([ ('status', 'foo', 'exists', None, True, None, None, False, None, None, None), ], result._events)
def check_events(self, source_bytes, events): source = BytesIO(source_bytes) result = doubles.StreamResult() v2.ByteStreamToStreamResult(source, non_subunit_name="stdout").run(result) self.assertEqual(b'', source.read()) self.assertEqual(events, result._events) # any file attachments should be byte contents [as users assume that]. for event in result._events: if event[5] is not None: self.assertIsInstance(event[6], bytes)
def get_result_for(commands): """Get a result object from *commands. Runs the 'generate_stream_results' function from subunit._output after parsing *commands as if they were specified on the command line. The resulting bytestream is then converted back into a result object and returned. """ result = doubles.StreamResult() args = safe_parse_arguments(commands) _output.generate_stream_results(args, result) return result
def test_default(self): byte_stream = compat.BytesIO() stream = v2.StreamResultToBytes(byte_stream) stream.status(test_id="foo", test_status="inprogress") stream.status(test_id="foo", test_status="skip") output = self.run_command([], byte_stream.getvalue()) events = doubles.StreamResult() v2.ByteStreamToStreamResult(compat.BytesIO(output)).run(events) self.assertEqual([ ('status', 'foo', 'inprogress'), ('status', 'foo', 'skip'), ], [event[:3] for event in events._events])
def test_signature_middle_utf8_char(self): utf8_bytes = b'\xe3\xb3\x8a' source = BytesIO(utf8_bytes) # Should be treated as one character (it is u'\u3cca') and wrapped result = doubles.StreamResult() v2.ByteStreamToStreamResult(source, non_subunit_name="stdout").run(result) self.assertEqual([ ('status', None, None, None, True, 'stdout', b'\xe3', False, None, None, None), ('status', None, None, None, True, 'stdout', b'\xb3', False, None, None, None), ('status', None, None, None, True, 'stdout', b'\x8a', False, None, None, None), ], result._events)
def test_todo_and_skip(self): # A file # not ok 1 - a fail # not ok 2 - another fail # SKIP instead # results in two tests, numbered and commented. self.tap.write(compat._u("not ok 1 - a fail but # TODO but is TODO\n")) self.tap.write(compat._u("not ok 2 - another fail # SKIP instead\n")) self.tap.seek(0) result = pysubunit.TAP2SubUnit(self.tap, self.subunit) self.assertEqual(0, result) self.subunit.seek(0) events = doubles.StreamResult() v2.ByteStreamToStreamResult(self.subunit).run(events) self.check_events([('status', 'test 1 - a fail but', 'xfail', None, False, 'tap comment', b'but is TODO', True, 'text/plain; charset=UTF8', None, None), ('status', 'test 2 - another fail', 'skip', None, False, 'tap comment', b'instead', True, 'text/plain; charset=UTF8', None, None)])
def test_tags(self): byte_stream = compat.BytesIO() stream = v2.StreamResultToBytes(byte_stream) stream.status(test_id="foo", test_status="inprogress", test_tags=set(["a"])) stream.status(test_id="foo", test_status="success", test_tags=set(["a"])) stream.status(test_id="bar", test_status="inprogress") stream.status(test_id="bar", test_status="inprogress") stream.status(test_id="baz", test_status="inprogress", test_tags=set(["a"])) stream.status(test_id="baz", test_status="success", test_tags=set(["a"])) output = self.run_command(['-s', '--with-tag', 'a'], byte_stream.getvalue()) events = doubles.StreamResult() v2.ByteStreamToStreamResult(compat.BytesIO(output)).run(events) ids = set(event[1] for event in events._events) self.assertEqual(set(['foo', 'baz']), ids)
def test_non_pysubunit_encapsulated(self): source = BytesIO(b"foo\nbar\n") result = doubles.StreamResult() v2.ByteStreamToStreamResult(source, non_subunit_name="stdout").run(result) self.assertEqual([ ('status', None, None, None, True, 'stdout', b'f', False, None, None, None), ('status', None, None, None, True, 'stdout', b'o', False, None, None, None), ('status', None, None, None, True, 'stdout', b'o', False, None, None, None), ('status', None, None, None, True, 'stdout', b'\n', False, None, None, None), ('status', None, None, None, True, 'stdout', b'b', False, None, None, None), ('status', None, None, None, True, 'stdout', b'a', False, None, None, None), ('status', None, None, None, True, 'stdout', b'r', False, None, None, None), ('status', None, None, None, True, 'stdout', b'\n', False, None, None, None), ], result._events) self.assertEqual(b'', source.read())
def check_events(self, events): self.subunit.seek(0) eventstream = doubles.StreamResult() v2.ByteStreamToStreamResult(self.subunit).run(eventstream) self.assertEqual(events, eventstream._events)
def test_hypothesis_decoding(self, code_bytes): source = BytesIO(code_bytes) result = doubles.StreamResult() stream = v2.ByteStreamToStreamResult(source, non_subunit_name="stdout") stream.run(result) self.assertEqual(b'', source.read())