def subunit2junitxml(ctr): from testtools import ExtendedToStreamDecorator from testtools import StreamToExtendedDecorator from subunit import StreamResultToBytes from subunit.filters import filter_by_result from subunit.filters import run_tests_from_stream from spyne.util.six import BytesIO from junitxml import JUnitXmlResult sys.argv = ['subunit-1to2'] subunit1_file_name = 'test_result.%d.subunit' % ctr subunit2 = BytesIO() run_tests_from_stream(open(subunit1_file_name, 'rb'), ExtendedToStreamDecorator(StreamResultToBytes(subunit2))) subunit2.seek(0) sys.argv = ['subunit2junitxml'] sys.stdin = subunit2 def f(output): return StreamToExtendedDecorator(JUnitXmlResult(output)) junit_file_name = 'test_result.%d.xml' % ctr filter_by_result(f, junit_file_name, True, False, protocol_version=2, passthrough_subunit=True, input_stream=subunit2)
def subunit2junitxml(ctr): from testtools import ExtendedToStreamDecorator from testtools import StreamToExtendedDecorator from subunit import StreamResultToBytes from subunit.filters import filter_by_result from subunit.filters import run_tests_from_stream from spyne.util.six import BytesIO from junitxml import JUnitXmlResult sys.argv = ['subunit-1to2'] subunit1_file_name = 'test_result.%d.subunit' % ctr subunit2 = BytesIO() run_tests_from_stream(open(subunit1_file_name, 'rb'), ExtendedToStreamDecorator( StreamResultToBytes(subunit2))) subunit2.seek(0) sys.argv = ['subunit2junitxml'] sys.stdin = subunit2 def f(output): return StreamToExtendedDecorator(JUnitXmlResult(output)) junit_file_name = 'test_result.%d.xml' % ctr filter_by_result(f, junit_file_name, True, False, protocol_version=2, passthrough_subunit=True, input_stream=subunit2)
def to_disk(argv=None, stdin=None, stdout=None): if stdout is None: stdout = sys.stdout if stdin is None: stdin = sys.stdin parser = optparse.OptionParser( description="Export a subunit stream to files on disk.", epilog=dedent("""\ Creates a directory per test id, a JSON file with test metadata within that directory, and each attachment is written to their name relative to that directory. Global packages (no test id) are discarded. Exits 0 if the export was completed, or non-zero otherwise. """)) parser.add_option("-d", "--directory", help="Root directory to export to.", default=".") options, args = parser.parse_args(argv) if len(args) > 1: raise Exception("Unexpected arguments.") if len(args): source = io.open(args[0], 'rb') else: source = stdin exporter = DiskExporter(options.directory) result = StreamToDict(exporter.export) run_tests_from_stream(source, result, protocol_version=2) return 0
def to_disk(argv=None, stdin=None, stdout=None): if stdout is None: stdout = sys.stdout if stdin is None: stdin = sys.stdin parser = optparse.OptionParser( description="Export a subunit stream to files on disk.", epilog=dedent("""\ Creates a directory per test id, a JSON file with test metadata within that directory, and each attachment is written to their name relative to that directory. Global packages (no test id) are discarded. Exits 0 if the export was completed, or non-zero otherwise. """)) parser.add_option( "-d", "--directory", help="Root directory to export to.", default=".") options, args = parser.parse_args(argv) if len(args) > 1: raise Exception("Unexpected arguments.") if len(args): source = io.open(args[0], 'rb') else: source = stdin exporter = DiskExporter(options.directory) result = StreamToDict(exporter.export) run_tests_from_stream(source, result, protocol_version=2) return 0
def filter_by_result( result_factory, output_path, passthrough, forward, input_stream=sys.stdin, protocol_version=1, passthrough_subunit=True, ): """Filter an input stream using a test result. :param result_factory: A callable that when passed an output stream returns a TestResult. It is expected that this result will output to the given stream. :param output_path: A path send output to. If None, output will be go to ``sys.stdout``. :param passthrough: If True, all non-subunit input will be sent to ``sys.stdout``. If False, that input will be discarded. :param forward: If True, all subunit input will be forwarded directly to ``sys.stdout`` as well as to the ``TestResult``. :param input_stream: The source of subunit input. Defaults to ``sys.stdin``. :param protocol_version: The subunit protocol version to expect. :param passthrough_subunit: If True, passthrough should be as subunit. :return: A test result with the results of the run. """ if protocol_version == 1: sys.stderr.write("Subunit protocol version 2 must be used") sys.exit(1) if passthrough: passthrough_stream = sys.stdout else: passthrough_stream = None if forward: forward_stream = sys.stdout else: forward_stream = None if output_path is None: output_to = sys.stdout else: output_to = open(output_path, "w") try: result = result_factory(output_to) run_tests_from_stream( input_stream, result, passthrough_stream, forward_stream, protocol_version=protocol_version, passthrough_subunit=passthrough_subunit, ) finally: if output_path: output_to.close() return result
def parse(self): _execution_date, _unixtime = get_date_from_source(self.source) _execution_name = self.source.name + _execution_date run_tests_from_stream( self.source, StreamToExtendedDecorator(TParserResult(_execution_name, self.tm)), protocol_version=2, passthrough_subunit=False ) print("\n...done") self.add_execution( _execution_name, _execution_date, 'n/a', _unixtime ) return