def test_with_subunit_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) inserter = repo.get_inserter() inserter.startTestRun() inserter.status(test_id='failing', test_status='fail') inserter.status(test_id='ok', test_status='success') inserter.stopTestRun() self.assertEqual(0, cmd.execute()) self.assertEqual(1, len(ui.outputs)) self.assertEqual('stream', ui.outputs[0][0]) as_subunit = BytesIO(ui.outputs[0][1]) stream = ByteStreamToStreamResult(as_subunit) log = StreamResult() log.startTestRun() try: stream.run(log) finally: log.stopTestRun() self.assertEqual([tuple(ev) for ev in log._events], [('startTestRun', ), ('status', 'failing', 'inprogress', None, True, None, None, False, None, None, Wildcard), ('status', 'failing', 'fail', None, True, None, None, False, None, None, Wildcard), ('stopTestRun', )])
def test_with_subunit_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) inserter = repo.get_inserter() inserter.startTestRun() inserter.status(test_id='failing', test_status='fail') inserter.status(test_id='ok', test_status='success') inserter.stopTestRun() self.assertEqual(0, cmd.execute()) self.assertEqual(1, len(ui.outputs)) self.assertEqual('stream', ui.outputs[0][0]) as_subunit = BytesIO(ui.outputs[0][1]) stream = ByteStreamToStreamResult(as_subunit) log = StreamResult() log.startTestRun() try: stream.run(log) finally: log.stopTestRun() self.assertEqual( log._events, [ ('startTestRun',), ('status', 'failing', 'inprogress', None, True, None, None, False, None, None, Wildcard), ('status', 'failing', 'fail', None, True, None, None, False, None, None, Wildcard), ('stopTestRun',) ])
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) as_subunit = BytesIO(ui.outputs[0][1]) stream = ByteStreamToStreamResult(as_subunit) log = StreamResult() log.startTestRun() try: stream.run(log) finally: log.stopTestRun() self.assertEqual( log._events, [ ('startTestRun',), ('status', 'failing', 'fail', None, True, None, None, False, None, None, None), ('status', 'ok', 'success', None, True, None, None, False, None, None, None), ('stopTestRun',) ])
def close_file(self, file_): """ Close and check the file """ file_.seek(0) case = ByteStreamToStreamResult(file_) result = StreamToDict(self.handle_dict) result.startTestRun() case.run(result) result.stopTestRun() file_.close()
def main(): parser = make_options() (options, args) = parser.parse_args() output = subunit_v2.StreamResultToBytes(sys.stdout) shouldfail = read_shouldfail_file(options) result = ProcessedStreamResult(output, shouldfail) converter = ByteStreamToStreamResult(source=sys.stdin, non_subunit_name='process-stderr') result.startTestRun() converter.run(result) result.stopTestRun()
def tag_stream(original, filtered, tags): """Alter tags on a stream. :param original: The input stream. :param filtered: The output stream. :param tags: The tags to apply. As in a normal stream - a list of 'TAG' or '-TAG' commands. A 'TAG' command will add the tag to the output stream, and override any existing '-TAG' command in that stream. Specifically: * A global 'tags: TAG' will be added to the start of the stream. * Any tags commands with -TAG will have the -TAG removed. A '-TAG' command will remove the TAG command from the stream. Specifically: * A 'tags: -TAG' command will be added to the start of the stream. * Any 'tags: TAG' command will have 'TAG' removed from it. Additionally, any redundant tagging commands (adding a tag globally present, or removing a tag globally removed) are stripped as a by-product of the filtering. :return: 0 """ new_tags, gone_tags = tags_to_new_gone(tags) source = ByteStreamToStreamResult(original, non_subunit_name='stdout') class Tagger(CopyStreamResult): def status(self, **kwargs): tags = kwargs.get('test_tags') if not tags: tags = set() tags.update(new_tags) tags.difference_update(gone_tags) if tags: kwargs['test_tags'] = tags else: kwargs['test_tags'] = None super(Tagger, self).status(**kwargs) output = Tagger([StreamResultToBytes(filtered)]) source.run(output) return 0
def tag_stream(original, filtered, tags): """Alter tags on a stream. :param original: The input stream. :param filtered: The output stream. :param tags: The tags to apply. As in a normal stream - a list of 'TAG' or '-TAG' commands. A 'TAG' command will add the tag to the output stream, and override any existing '-TAG' command in that stream. Specifically: * A global 'tags: TAG' will be added to the start of the stream. * Any tags commands with -TAG will have the -TAG removed. A '-TAG' command will remove the TAG command from the stream. Specifically: * A 'tags: -TAG' command will be added to the start of the stream. * Any 'tags: TAG' command will have 'TAG' removed from it. Additionally, any redundant tagging commands (adding a tag globally present, or removing a tag globally removed) are stripped as a by-product of the filtering. :return: 0 """ new_tags, gone_tags = tags_to_new_gone(tags) source = ByteStreamToStreamResult(original, non_subunit_name="stdout") class Tagger(CopyStreamResult): def status(self, **kwargs): tags = kwargs.get("test_tags") if not tags: tags = set() tags.update(new_tags) tags.difference_update(gone_tags) if tags: kwargs["test_tags"] = tags else: kwargs["test_tags"] = None super(Tagger, self).status(**kwargs) output = Tagger([StreamResultToBytes(filtered)]) source.run(output) return 0
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) as_subunit = BytesIO(ui.outputs[0][1]) stream = ByteStreamToStreamResult(as_subunit) log = StreamResult() log.startTestRun() try: stream.run(log) finally: log.stopTestRun() self.assertEqual(log._events, [('startTestRun', ), ('status', 'failing', 'fail', None, True, None, None, False, None, None, None), ('status', 'ok', 'success', None, True, None, None, False, None, None, None), ('stopTestRun', )])