Skip to content

Commit

Permalink
Merge pull request #47 from MaksimMisin/prettier-multiline-string-diff
Browse files Browse the repository at this point in the history
Better visualize differences in multiline strings
  • Loading branch information
hjwp authored Apr 15, 2024
2 parents 3ed5767 + 80458c2 commit 745b476
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pytest_icdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ def pytest_assertrepr_compare(config, op, left, right):
half_cols = COLS / 2 - MARGINS
TABSIZE = int(config.getoption("--icdiff-tabsize") or 2)

pretty_left = pformat(left, indent=TABSIZE, width=half_cols).splitlines()
pretty_right = pformat(right, indent=TABSIZE, width=half_cols).splitlines()
if isinstance(left, str) and isinstance(right, str):
pretty_left = left.splitlines()
pretty_right = right.splitlines()
else:
pretty_left = pformat(left, indent=TABSIZE, width=half_cols).splitlines()
pretty_right = pformat(right, indent=TABSIZE, width=half_cols).splitlines()
diff_cols = COLS - MARGINS

if len(pretty_left) < 3 or len(pretty_right) < 3:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_pytest_icdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,21 @@ def test_one():
assert comparison_line.count("hell") < 15


def test_mutliline_strings_have_no_escaped_newlines(testdir):
testdir.makepyfile(
r"""
def test_one():
one = "a\nb\nc\nd"
two = "a\nb\nc\ndd"
assert one == two"""
)
output = testdir.runpytest("-vv", "--color=yes").stdout.str()
print(repr(output))
assert "a" + " " * 36 in output
assert "b" + " " * 36 in output
assert "c" + " " * 36 in output


def test_columns_are_calculated_outside_hook(testdir):
"""
ok for some reason if you get the TerminalWriter width
Expand Down

0 comments on commit 745b476

Please sign in to comment.