def _iter_streams(self, stream_type): # Only the first stream declared in a command can be accepted at the # moment - as there is only one stdin and alternate streams are not yet # configurable in the CLI. first_stream_type = self.cmd.input_streams[0] if (stream_type != first_stream_type and stream_type != first_stream_type[:-1]): return yield subunit.make_stream_binary(self._stdin)
def __init__(self, output_stream): """Create a StreamResultToBytes with output written to output_stream. :param output_stream: A file-like object. Must support write(bytes) and flush() methods. Flush will be called after each write. The stream will be passed through subunit.make_stream_binary, to handle regular cases such as stdout. """ self.output_stream = subunit.make_stream_binary(output_stream)
def _iter_streams(self, stream_type): # Only the first stream declared in a command can be accepted at the # moment - as there is only one stdin and alternate streams are not yet # configurable in the CLI. first_stream_type = self.cmd.input_streams[0] if (stream_type != first_stream_type and stream_type != first_stream_type[:-1]): return yield subunit.make_stream_binary(self._stdin)
def __init__(self, output_stream): """Create a StreamResultToBytes with output written to output_stream. :param output_stream: A file-like object. Must support write(bytes) and flush() methods. Flush will be called after each write. The stream will be passed through subunit.make_stream_binary, to handle regular cases such as stdout. """ self.output_stream = subunit.make_stream_binary(output_stream)
def output_stream(stream, output=sys.stdout): _binary_stdout = subunit.make_stream_binary(output) contents = stream.read(65536) assert type(contents) is bytes, \ "Bad stream contents %r" % type(contents) # If there are unflushed bytes in the text wrapper, we need to sync.. output.flush() while contents: _binary_stdout.write(contents) contents = stream.read(65536) _binary_stdout.flush()
def output_stream(self, stream): if not self._binary_stdout: self._binary_stdout = subunit.make_stream_binary(self._stdout) contents = stream.read(65536) assert type(contents) is bytes, \ "Bad stream contents %r" % type(contents) # If there are unflushed bytes in the text wrapper, we need to sync.. self._stdout.flush() while contents: self._binary_stdout.write(contents) contents = stream.read(65536) self._binary_stdout.flush()
def output_stream(self, stream): if not self._binary_stdout: self._binary_stdout = subunit.make_stream_binary(self._stdout) contents = stream.read(65536) assert type(contents) is bytes, \ "Bad stream contents %r" % type(contents) # If there are unflushed bytes in the text wrapper, we need to sync.. self._stdout.flush() while contents: self._binary_stdout.write(contents) contents = stream.read(65536) self._binary_stdout.flush()
def __init__(self, source, non_subunit_name=None): """Create a ByteStreamToStreamResult. :param source: A file like object to read bytes from. Must support read(<count>) and return bytes. The file is not closed by ByteStreamToStreamResult. subunit.make_stream_binary() is called on the stream to get it into bytes mode. :param non_subunit_name: If set to non-None, non subunit content encountered in the stream will be converted into file packets labelled with this name. """ self.non_subunit_name = non_subunit_name self.source = subunit.make_stream_binary(source) self.codec = codecs.lookup('utf8').incrementaldecoder()
def __init__(self, source, non_subunit_name=None): """Create a ByteStreamToStreamResult. :param source: A file like object to read bytes from. Must support read(<count>) and return bytes. The file is not closed by ByteStreamToStreamResult. subunit.make_stream_binary() is called on the stream to get it into bytes mode. :param non_subunit_name: If set to non-None, non subunit content encountered in the stream will be converted into file packets labelled with this name. """ self.non_subunit_name = non_subunit_name self.source = subunit.make_stream_binary(source) self.codec = codecs.lookup('utf8').incrementaldecoder()
def __init__(self, byte_stream): self.stream = subunit.make_stream_binary(byte_stream)
def __init__(self, byte_stream): self.stream = subunit.make_stream_binary(byte_stream) self.last_file = None
def parse_arguments(args=None, ParserClass=OptionParser): """Parse arguments from the command line. If specified, args must be a list of strings, similar to sys.argv[1:]. ParserClass may be specified to override the class we use to parse the command-line arguments. This is useful for testing. """ parser = ParserClass( prog="subunit-output", description="A tool to generate a subunit v2 result byte-stream", usage="subunit-output [-h] [status TEST_ID] [options]", ) parser.set_default('tags', None) parser.set_default('test_id', None) status_commands = OptionGroup( parser, "Status Commands", "These options report the status of a test. TEST_ID must be a string " "that uniquely identifies the test." ) for action_name in _ALL_ACTIONS: status_commands.add_option( "--%s" % action_name, nargs=1, action="callback", callback=set_status_cb, callback_args=(action_name,), dest="action", metavar="TEST_ID", help="Report a test status." ) parser.add_option_group(status_commands) file_commands = OptionGroup( parser, "File Options", "These options control attaching data to a result stream. They can " "either be specified with a status command, in which case the file " "is attached to the test status, or by themselves, in which case " "the file is attached to the stream (and not associated with any " "test id)." ) file_commands.add_option( "--attach-file", help="Attach a file to the result stream for this test. If '-' is " "specified, stdin will be read instead. In this case, the file " "name will be set to 'stdin' (but can still be overridden with " "the --file-name option)." ) file_commands.add_option( "--file-name", help="The name to give this file attachment. If not specified, the " "name of the file on disk will be used, or 'stdin' in the case " "where '-' was passed to the '--attach-file' argument. This option" " may only be specified when '--attach-file' is specified.", ) file_commands.add_option( "--mimetype", help="The mime type to send with this file. This is only used if the " "--attach-file argument is used. This argument is optional. If it " "is not specified, the file will be sent without a mime type. This " "option may only be specified when '--attach-file' is specified.", default=None ) parser.add_option_group(file_commands) parser.add_option( "--tag", help="Specifies a tag. May be used multiple times", action="append", dest="tags", default=[] ) (options, args) = parser.parse_args(args) if options.mimetype and not options.attach_file: parser.error("Cannot specify --mimetype without --attach-file") if options.file_name and not options.attach_file: parser.error("Cannot specify --file-name without --attach-file") if options.attach_file: if options.attach_file == '-': if not options.file_name: options.file_name = 'stdin' options.attach_file = make_stream_binary(sys.stdin) else: try: options.attach_file = open(options.attach_file, 'rb') except IOError as e: parser.error("Cannot open %s (%s)" % (options.attach_file, e.strerror)) return options
def __init__(self, byte_stream): self.stream = subunit.make_stream_binary(byte_stream) self.last_file = None
def __init__(self, test_manager, source): super(SubunitImporter, self).__init__(test_manager, source) self.source = make_stream_binary(source)