Skip to content

Commit 89b8fc5

Browse files
committed
handle case with long lines in comparators
1 parent 73f7b60 commit 89b8fc5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

pytest_icdiff.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pylint: disable=inconsistent-return-statements
12
from pprintpp import pformat
23
import icdiff
34

@@ -22,7 +23,8 @@ def pytest_assertrepr_compare(config, op, left, right):
2223
shortest_right = pformat(right, indent=2, width=1).splitlines()
2324
cols = max(len(l) for l in shortest_left + shortest_right) * 2
2425
else:
25-
cols = max(len(l) for l in wide_left + wide_right) * 2
26+
longest_line_length = max(len(l) for l in wide_left + wide_right)
27+
cols = int(min(longest_line_length, cols / 2))
2628

2729
pretty_left = pformat(left, indent=2, width=cols / 2).splitlines()
2830
pretty_right = pformat(right, indent=2, width=cols / 2).splitlines()

tests/test_pytest_icdiff.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,17 @@ def test_a():
188188
output = testdir.runpytest().stdout.str()
189189
drilldown_expression = 'where 3 = len([1, 2, 3])'
190190
assert drilldown_expression in output
191+
192+
193+
def test_long_lines_in_comparators_are_wrapped_sensibly(testdir):
194+
left = {1: "hello " * 20}
195+
right = {1: "hella " * 20}
196+
testdir.makepyfile(
197+
f"""
198+
def test_one():
199+
assert {left!r} == {right!r}
200+
"""
201+
)
202+
output = testdir.runpytest('-vv', '--color=yes').stdout.str()
203+
comparison_line = next(l for l in output.splitlines() if '1:' in l and "assert" not in l)
204+
assert len(comparison_line) < 120

0 commit comments

Comments
 (0)