def load(force_init=False, in_streams=None, partial=False, subunit_out=False, repo_type='file', repo_url=None, run_id=None, streams=None, pretty_out=False, color=False, stdout=sys.stdout, abbreviate=False, suppress_attachments=False, serial=False, all_attachments=False): """Load subunit streams into a repository This function will load subunit streams into the repository. It will output to STDOUT the results from the input stream. Internally this is used by the run command to both output the results as well as store the result in the repository. :param bool force_init: Initialize the specifiedrepository if it hasn't been created. :param list in_streams: A list of file objects that will be saved into the repository :param bool partial: DEPRECATED: Specify the input is a partial stream. This option is deprecated and no longer does anything. It will be removed in the future. :param bool subunit_out: Output the subunit stream to stdout :param str repo_type: This is the type of repository to use. Valid choices are 'file' and 'sql'. :param str repo_url: The url of the repository to use. :param run_id: The optional run id to save the subunit stream to. :param list streams: A list of file paths to read for the input streams. :param bool pretty_out: Use the subunit-trace output filter for the loaded stream. :param bool color: Enabled colorized subunit-trace output :param file stdout: The output file to write all output to. By default this is sys.stdout :param bool abbreviate: Use abbreviated output if set true :param bool suppress_attachments: When set true attachments subunit_trace will not print attachments on successful test execution. :param bool all_attachments: When set true subunit_trace will print all text attachments on successful test execution. :return return_code: The exit code for the command. 0 for success and > 0 for failures. :rtype: int """ if partial: warnings.warn('The partial flag is deprecated and has no effect ' 'anymore') try: repo = util.get_repo_open(repo_type, repo_url) except repository.RepositoryNotFound: if force_init: repo = util.get_repo_initialise(repo_type, repo_url) else: raise # Not a full implementation of TestCase, but we only need to iterate # back to it. Needs to be a callable - its a head fake for # testsuite.add. if in_streams: streams = utils.iter_streams(in_streams, 'subunit') elif streams: opener = functools.partial(open, mode='rb') streams = map(opener, streams) else: streams = [sys.stdin] def mktagger(pos, result): return testtools.StreamTagger([result], add=['worker-%d' % pos]) def make_tests(): for pos, stream in enumerate(streams): # Calls StreamResult API. case = subunit.ByteStreamToStreamResult(stream, non_subunit_name='stdout') decorate = functools.partial(mktagger, pos) case = testtools.DecorateTestCaseResult(case, decorate) yield (case, str(pos))
def load(force_init=False, in_streams=None, subunit_out=False, repo_url=None, run_id=None, streams=None, pretty_out=False, color=False, stdout=sys.stdout, abbreviate=False, suppress_attachments=False, serial=False, all_attachments=False, show_binary_attachments=False): """Load subunit streams into a repository This function will load subunit streams into the repository. It will output to STDOUT the results from the input stream. Internally this is used by the run command to both output the results as well as store the result in the repository. :param bool force_init: Initialize the specified repository if it hasn't been created. :param list in_streams: A list of file objects that will be saved into the repository :param bool subunit_out: Output the subunit stream to stdout :param str repo_url: The url of the repository to use. :param run_id: The optional run id to save the subunit stream to. :param list streams: A list of file paths to read for the input streams. :param bool pretty_out: Use the subunit-trace output filter for the loaded stream. :param bool color: Enabled colorized subunit-trace output :param file stdout: The output file to write all output to. By default this is sys.stdout :param bool abbreviate: Use abbreviated output if set true :param bool suppress_attachments: When set true attachments subunit_trace will not print attachments on successful test execution. :param bool all_attachments: When set true subunit_trace will print all text attachments on successful test execution. :param bool show_binary_attachments: When set to true, subunit_trace will print binary attachments in addition to text attachments. :return return_code: The exit code for the command. 0 for success and > 0 for failures. :rtype: int """ try: repo = util.get_repo_open(repo_url=repo_url) except repository.RepositoryNotFound: if force_init: try: repo = util.get_repo_initialise(repo_url=repo_url) except OSError as e: if e.errno != errno.EEXIST: raise repo_path = repo_url or './stestr' stdout.write('The specified repository directory %s already ' 'exists. Please check if the repository already ' 'exists or select a different path\n' % repo_path) exit(1) else: raise # Not a full implementation of TestCase, but we only need to iterate # back to it. Needs to be a callable - its a head fake for # testsuite.add. if in_streams: streams = utils.iter_streams(in_streams, 'subunit') elif streams: opener = functools.partial(open, mode='rb') streams = map(opener, streams) else: streams = [sys.stdin] def mktagger(pos, result): return testtools.StreamTagger([result], add=['worker-%d' % pos]) def make_tests(): for pos, stream in enumerate(streams): # Calls StreamResult API. case = subunit.ByteStreamToStreamResult(stream, non_subunit_name='stdout') decorate = functools.partial(mktagger, pos) case = testtools.DecorateTestCaseResult(case, decorate) yield (case, str(pos))