Adding whitespace escaping on difference display
This commit is contained in:
parent
fdb8bbf154
commit
85efd70a71
1
AUTHORS
1
AUTHORS
|
@ -284,6 +284,7 @@ Nicolas Delaby
|
||||||
Nikolay Kondratyev
|
Nikolay Kondratyev
|
||||||
Nipunn Koorapati
|
Nipunn Koorapati
|
||||||
Oleg Pidsadnyi
|
Oleg Pidsadnyi
|
||||||
|
Oleg Plisov
|
||||||
Oleg Sushchenko
|
Oleg Sushchenko
|
||||||
Olga Matoula
|
Olga Matoula
|
||||||
Oliver Bestwalter
|
Oliver Bestwalter
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Terminal outputting string difference will now escape whitespace characters if those are the difference
|
|
@ -305,10 +305,22 @@ def _diff_text(left: str, right: str, verbose: int = 0) -> List[str]:
|
||||||
left = left[:-i]
|
left = left[:-i]
|
||||||
right = right[:-i]
|
right = right[:-i]
|
||||||
keepends = True
|
keepends = True
|
||||||
|
diffspace = False
|
||||||
|
for i in range(min(len(left), len(right))):
|
||||||
|
if left[i] != right[i]:
|
||||||
|
if left[i].isspace() and right[i].isspace():
|
||||||
|
diffspace = True # Check if difference in strings is whitespace symbol
|
||||||
|
break
|
||||||
if left.isspace() or right.isspace():
|
if left.isspace() or right.isspace():
|
||||||
left = repr(str(left))
|
left = repr(str(left))
|
||||||
right = repr(str(right))
|
right = repr(str(right))
|
||||||
explanation += ["Strings contain only whitespace, escaping them using repr()"]
|
explanation += ["Strings contain only whitespace, escaping them using repr()"]
|
||||||
|
elif diffspace:
|
||||||
|
left = repr(str(left))
|
||||||
|
right = repr(str(right))
|
||||||
|
explanation += [
|
||||||
|
"Strings are different by whitespaces, escaping them using repr()"
|
||||||
|
]
|
||||||
# "right" is the expected base against which we compare "left",
|
# "right" is the expected base against which we compare "left",
|
||||||
# see https://github.com/pytest-dev/pytest/issues/3333
|
# see https://github.com/pytest-dev/pytest/issues/3333
|
||||||
explanation += [
|
explanation += [
|
||||||
|
|
|
@ -262,6 +262,20 @@ TESTCASES = [
|
||||||
""",
|
""",
|
||||||
id="Compare attrs classes",
|
id="Compare attrs classes",
|
||||||
),
|
),
|
||||||
|
pytest.param(
|
||||||
|
"""
|
||||||
|
def test_this():
|
||||||
|
assert "word\t" == "word "
|
||||||
|
""",
|
||||||
|
"""
|
||||||
|
> assert "word\t" == "word "
|
||||||
|
E AssertionError: assert 'word\\t' == 'word '
|
||||||
|
E Strings are different by whitespaces, escaping them using repr()
|
||||||
|
E - 'word '
|
||||||
|
E + 'word\\t'
|
||||||
|
""",
|
||||||
|
id="Compare whitespaces",
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue