Example #1
0
def pytest_assertrepr_compare(config, op, left, right):
    """
    When asserting equality between process results, show detailed differences.
    """
    checks = (op == '==', isinstance(left, GipsProcResult),
              isinstance(right, GipsProcResult))
    if not all(checks):
        return

    def header_and_indent(header, lines):
        if lines:
            return [header + ':'] + ['  ' + line for line in lines]
        else:
            return [header + ':  matches']

    verbose = config.getoption('verbose')

    output = ['GipsProcResult == GipsProcResult:']

    oper = {True: '==', False: '!='}[left.exit_status == right.exit_status]
    output += [
        'exit_status:  {} {} {}'.format(left.exit_status, oper,
                                        right.exit_status)
    ]

    for s in ('stdout', 'stderr'):
        l_compare = getattr(left, 'compare_' + s)
        r_compare = getattr(right, 'compare_' + s)
        if l_compare and r_compare:
            (l_stream, r_stream) = (getattr(left, s), getattr(right, s))
            # TODO text diff breaks due to terminal control sequences (I
            # think it's escaping them wrong or not at all).
            output += header_and_indent(
                s, _diff_text(l_stream, r_stream, verbose))
        else:
            output += [s + ':  ignored']

    updated_diff = _compare_eq_dict(left.strip_ignored(left.updated),
                                    left.strip_ignored(right.updated), verbose)
    deleted_diff = _compare_eq_dict(left.strip_ignored(left.deleted),
                                    left.strip_ignored(right.deleted), verbose)
    created_diff = _compare_eq_dict(left.strip_ignored(left.created),
                                    left.strip_ignored(right.created), verbose)
    output += header_and_indent('updated', updated_diff)
    output += header_and_indent('deleted', deleted_diff)
    output += header_and_indent('created', created_diff)
    output += header_and_indent('ignored', left.ignored)

    return output
Example #2
0
def _verify_environ(_collected_environ):
    try:
        yield
    finally:
        new_environ = dict(os.environ)
        current_test = new_environ.pop('PYTEST_CURRENT_TEST', None)
        old_environ = dict(_collected_environ)
        old_environ.pop('PYTEST_CURRENT_TEST', None)
        if new_environ != old_environ:
            raise DirtyTest(
                'Left over environment variables', current_test,
                _compare_eq_dict(new_environ, old_environ, verbose=2))
Example #3
0
def pytest_assertrepr_compare(config, op, left, right):
    """When asserting equality between process results, show detailed differences."""
    checks = (op == '==', isinstance(left, GipsProcResult), isinstance(right, GipsProcResult))
    if not all(checks):
        return

    def header_and_indent(header, lines):
        if lines:
            return [header + ':'] + ['  ' + line for line in lines]
        else:
            return [header + ':  matches']

    verbose = config.getoption('verbose')

    output = ['GipsProcResult == GipsProcResult:']

    oper = {True: '==', False: '!='}[left.exit_status == right.exit_status]
    output += ['exit_status:  {} {} {}'.format(left.exit_status, oper, right.exit_status)]

    # TODO text diff breaks due to terminal control sequences (I
    # think it's escaping them wrong or not at all).
    if left.compare_stdout:
        stdout_diff = _diff_text(left.stdout, right.stdout, verbose)
        output += header_and_indent('stdout', stdout_diff)
    else:
        output += ['stdout:  ignored']

    stderr_diff  = _diff_text(left.stderr, right.stderr, verbose)
    updated_diff = _compare_eq_dict(left.updated, right.updated, verbose)
    deleted_diff = _compare_eq_dict(left.deleted, right.deleted, verbose)
    created_diff = _compare_eq_dict(left.created, right.created, verbose)

    output += header_and_indent('stderr', stderr_diff)
    output += header_and_indent('updated', updated_diff)
    output += header_and_indent('deleted', deleted_diff)
    output += header_and_indent('created', created_diff)

    return output