Skip to content

Better visualize differences in multiline strings #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +242 to +244
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't quite understand what these asserts are doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's to make sure that there're actually empty spaces instead of new lines after last characters on the line
image

before it looked like this:
image
so this test would fail

36 should be slightly above the actual size of these columns, with some margins in case icdiff implementation changes a bit.



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