Beispiel #1
0
def run(arguments):
    args = arguments[0]
    repo = util.get_repo_open(args.repo_type, args.repo_url)
    latest_run = repo.get_latest_run()
    if args.subunit:
        stream = latest_run.get_subunit_stream()
        output.output_stream(stream)
        # Exits 0 if we successfully wrote the stream.
        return 0
    case = latest_run.get_test()
    try:
        if args.repo_type == 'file':
            previous_run = repo.get_test_run(repo.latest_id() - 1)
        # TODO(mtreinish): add a repository api to get the previous_run to
        # unify this logic
        else:
            previous_run = None
    except KeyError:
        previous_run = None
    failed = False
    output_result = results.CLITestResult(latest_run.get_id, sys.stdout,
                                          previous_run)
    summary = output_result.get_summary()
    output_result.startTestRun()
    try:
        case.run(output_result)
Beispiel #2
0
def _make_result(repo, list_tests=False):
    if list_tests:
        list_result = testtools.StreamSummary()
        return list_result, list_result
    else:

        def _get_id():
            return repo.get_latest_run().get_id()

        output_result = results.CLITestResult(_get_id, sys.stdout, None)
        summary_result = output_result.get_summary()
        return output_result, summary_result
Beispiel #3
0
                           stdout,
                           enable_color=color,
                           abbreviate=abbreviate,
                           suppress_attachments=suppress_attachments,
                           all_attachments=all_attachments))
     summary_result = testtools.StreamSummary()
     output_result = testtools.CopyStreamResult([outcomes, summary_result])
     output_result = testtools.StreamResultRouter(output_result)
     cat = subunit.test_results.CatFiles(stdout)
     output_result.add_rule(cat, 'test_id', test_id=None)
 else:
     try:
         previous_run = repo.get_latest_run()
     except KeyError:
         previous_run = None
     output_result = results.CLITestResult(inserter.get_id, stdout,
                                           previous_run)
     summary_result = output_result.get_summary()
 result = testtools.CopyStreamResult([inserter, output_result])
 result.startTestRun()
 try:
     case.run(result)
 finally:
     result.stopTestRun()
 if pretty_out and not subunit_out:
     start_times = []
     stop_times = []
     for worker in subunit_trace.RESULTS:
         for test in subunit_trace.RESULTS[worker]:
             if not test['timestamps'][0] or not test['timestamps'][1]:
                 continue
             start_times.append(test['timestamps'][0])
Beispiel #4
0
def last(repo_type='file', repo_url=None, subunit_out=False, pretty_out=True,
         color=False, stdout=sys.stdout, suppress_attachments=False):
    """Show the last run loaded into a a repository

    This function will print the results from the last run in the repository
    to STDOUT. It can optionally print the subunit stream for the last run
    to STDOUT if the ``subunit`` option is set to true.

    Note this function depends on the cwd for the repository if `repo_type` is
    set to file and `repo_url` is not specified it will use the repository
    located at CWD/.stestr

    :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 bool subunit_out: Show output as a subunit stream.
    :param pretty_out: Use the subunit-trace output filter.
    :param color: Enable colorized output with the subunit-trace output filter.
    :param bool subunit: Show output as a subunit stream.
    :param file stdout: The output file to write all output to. By default
         this is sys.stdout
    :param bool suppress_attachments: When set true attachments subunit_trace
        will not print attachments on successful test execution.

    :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_type, repo_url)
    except abstract.RepositoryNotFound as e:
        stdout.write(str(e) + '\n')
        return 1

    try:
        latest_run = repo.get_latest_run()
    except KeyError as e:
        stdout.write(str(e) + '\n')
        return 1

    if subunit_out:
        stream = latest_run.get_subunit_stream()
        output.output_stream(stream, output=stdout)
        # Exits 0 if we successfully wrote the stream.
        return 0
    case = latest_run.get_test()
    try:
        if repo_type == 'file':
            previous_run = repo.get_test_run(repo.latest_id() - 1)
        # TODO(mtreinish): add a repository api to get the previous_run to
        # unify this logic
        else:
            previous_run = None
    except KeyError:
        previous_run = None
    failed = False
    if not pretty_out:
        output_result = results.CLITestResult(latest_run.get_id, stdout,
                                              previous_run)
        summary = output_result.get_summary()
        output_result.startTestRun()
        try:
            case.run(output_result)
        finally:
Beispiel #5
0
def history_show(run_id,
                 repo_url=None,
                 subunit_out=False,
                 pretty_out=True,
                 color=False,
                 stdout=sys.stdout,
                 suppress_attachments=False,
                 all_attachments=False,
                 show_binary_attachments=False):
    """Show a run loaded into a repository

    This function will print the results from the last run in the repository
    to STDOUT. It can optionally print the subunit stream for the last run
    to STDOUT if the ``subunit`` option is set to true.

    Note this function depends on the cwd for the repository if `repo_url` is
    not specified it will use the repository located at CWD/.stestr

    :param str run_id: The run id to show
    :param str repo_url: The url of the repository to use.
    :param bool subunit_out: Show output as a subunit stream.
    :param pretty_out: Use the subunit-trace output filter.
    :param color: Enable colorized output with the subunit-trace output filter.
    :param bool subunit: Show output as a subunit stream.
    :param file stdout: The output file to write all output to. By default
         this is sys.stdout
    :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 abstract.RepositoryNotFound as e:
        stdout.write(str(e) + '\n')
        return 1
    try:
        if run_id:
            run = repo.get_test_run(run_id)
        else:
            run = repo.get_latest_run()
    except KeyError as e:
        stdout.write(str(e) + '\n')
        return 1

    if subunit_out:
        stream = run.get_subunit_stream()
        output.output_stream(stream, output=stdout)
        # Exits 0 if we successfully wrote the stream.
        return 0
    case = run.get_test()
    try:
        if run_id:
            previous_run = int(run_id) - 1
        else:
            previous_run = repo.get_test_run(repo.latest_id() - 1)
    except KeyError:
        previous_run = None
    failed = False
    if not pretty_out:
        output_result = results.CLITestResult(run.get_id, stdout, previous_run)
        summary = output_result.get_summary()
        output_result.startTestRun()
        try:
            case.run(output_result)
        finally: