Exemple #1
0
    def repr_failure(self, exc_info):
        if exc_info.errisinstance((ValueError,)):
            # Output is mismatching. Create a nice diff as failure description.
            expected, output = exc_info.value.args

            message = _diff_text(expected, output)
            return ReprFailExample(self.fspath.basename, self.lineno,
                    self.outputfile, message)
        elif exc_info.errisinstance((IOError,)):
            # Something wrent wrong causing an IOError.
            if exc_info.value.errno != errno.ENOENT:
                # This isn't a file not found error so bail out and report the
                # error in detail.
                return pytest.Item.repr_failure(self, exc_info)
            # Otherwise provide a concise error description.
            return ReprFileNotFoundExample(self.fspath.basename, self.lineno,
                    self.examplefile, exc_info)
        elif exc_info.errisinstance((subprocess.CalledProcessError,)):
            # Something wrent wrong while executing the example. Provide a
            # concise error description.
            return ReprErrorExample(self.fspath.basename, self.lineno,
                    self.examplefile, exc_info)
        else:
            # Something went terribly wrong :(
            return pytest.Item.repr_failure(self, exc_info)
Exemple #2
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
Exemple #3
0
    def repr_failure(self, exc_info):
        if exc_info.errisinstance(ValueError):
            # Output is mismatching. Create a nice diff as failure description.
            expected, output = exc_info.value.args
            message = _diff_text(output, expected)
            return ReprFailExample(self.pyfile, self.outfile, message)

        elif exc_info.errisinstance(subprocess.CalledProcessError):
            # Something wrent wrong while executing the example.
            return ReprErrorExample(self.pyfile, exc_info)

        else:
            # Something went terribly wrong :(
            return pytest.Item.repr_failure(self, exc_info)
Exemple #4
0
    def repr_failure(self, exc_info):
        if exc_info.errisinstance(ValueError):
            # Output is mismatching. Create a nice diff as failure description.
            expected, output = exc_info.value.args
            message = _diff_text(output, expected)
            return ReprFailExample(self.pyfile, self.outfile, message)

        elif exc_info.errisinstance(subprocess.CalledProcessError):
            # Something wrent wrong while executing the example.
            return ReprErrorExample(self.pyfile, exc_info)

        else:
            # Something went terribly wrong :(
            return pytest.Item.repr_failure(self, exc_info)
Exemple #5
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