Exemplo n.º 1
0
def pytest_assertrepr_compare(config, op, left, right):
    if config.getoption('-v') < 2:
        return

    op = display_op_for(op)

    width = int(config.getoption("--diff-width"))
    diff_type = config.getoption("--diff-type")

    lhs_repr = pformat_no_color(utf8_replace(left), width)
    rhs_repr = pformat_no_color(utf8_replace(right), width)

    if diff_type == "split":
        output = build_full_splitdiff_output(lhs_repr, rhs_repr, op)
    elif diff_type == "unified":
        output = build_full_unidiff_output(lhs_repr, rhs_repr, op)
    else:  # assume diff_type == "auto" so decide based on newlines
        if "\n" in lhs_repr and "\n" in rhs_repr:
            output = build_full_unidiff_output(lhs_repr, rhs_repr, op)
        else:
            output = build_full_splitdiff_output(lhs_repr, rhs_repr, op)

    if not config.getoption("--no-hints"):
        output += hints_for(op, left, right)

    return [utf8_replace(line) for line in output]
Exemplo n.º 2
0
def pytest_assertrepr_compare(config, op, left, right):
    if config.getoption("-v") < 2:
        return

    op = display_op_for(op)
    width = int(config.getoption("--diff-width"))
    show_symbols = bool(config.getoption("--diff-symbols"))

    diff = Diff(left, right, width, show_symbols)

    output = StringIO()
    console = Console(file=output, record=True)

    console.print("\n[green]LHS[/] vs [red]RHS[/] shown below\n")
    console.print(diff)

    diff_text = console.export_text(styles=True)

    return [
        f"{display_op_for(op)} failed. [pytest-clarity diff shown]",
        *[f"\033[0m{line}" for line in diff_text.split(f"\n")],
    ]
Exemplo n.º 3
0
 def _(arg=arg, result=result):
     assert display_op_for(arg) == result
Exemplo n.º 4
0
def test_display_op_for(arg, result):
    assert display_op_for(arg) == result