This commit is contained in:
mthaitan 2024-06-18 16:47:21 +02:00 committed by GitHub
commit bcc967c739
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 0 deletions

View File

@ -136,6 +136,7 @@ Eero Vaher
Eli Boyarski
Elizaveta Shashkova
Éloi Rivard
Emmeline Wetzel
Endre Galaczi
Eric Hunsberger
Eric Liu
@ -247,6 +248,7 @@ Loic Esteve
Lukas Bednar
Luke Murphy
Maciek Fijalkowski
Madeline Thai-Tang
Maho
Maik Figura
Mandeep Bhutani

View File

@ -0,0 +1 @@
Changed the diff explanation for string comparison assertions when there is a tab in the string to show ``\t`` instead of four spaces.

View File

@ -319,6 +319,10 @@ def _diff_text(left: str, right: str, verbose: int = 0) -> List[str]:
line.strip("\n")
for line in ndiff(right.splitlines(keepends), left.splitlines(keepends))
]
for i in range(len(explanation)):
if "? " not in explanation[i]: # dont replace diff message tab
explanation[i] = explanation[i].replace("+ ", "+ \\t")
explanation[i] = explanation[i].replace(" ", "\\t")
return explanation

View File

@ -282,6 +282,23 @@ TESTCASES = [
""",
id="Compare attrs classes",
),
pytest.param(
"""
def test_this():
result = '''spam bacon
eggs love'''
desired = "spam bacon eggs love"
assert result == desired
""",
"""
> assert result == desired
E AssertionError: assert 'spam bacon\\n eggs love' == 'spam bacon eggs love'
E - spam bacon eggs love
E + spam\\tbacon
E + \\teggs love
""",
id="Test tab repr in diff",
),
]