From 8c622d20ff603b2ce30a564267c3255c21d782c6 Mon Sep 17 00:00:00 2001 From: egwetzel Date: Mon, 1 May 2023 16:00:08 -0400 Subject: [PATCH 1/8] Added test to check error diffs with different spacing --- testing/test_error_diffs.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/testing/test_error_diffs.py b/testing/test_error_diffs.py index eb7812108..2bc58e0de 100644 --- a/testing/test_error_diffs.py +++ b/testing/test_error_diffs.py @@ -262,6 +262,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 bacon + E + eggs love + """, + id='Test "not in" string', + ), ] From 1e5fa13087aea69ec23b465904c27e2eee89fa7b Mon Sep 17 00:00:00 2001 From: egwetzel Date: Mon, 1 May 2023 16:42:13 -0400 Subject: [PATCH 2/8] Added testing to for our new functionality (functionality not implemented yet) --- testing/test_error_diffs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/test_error_diffs.py b/testing/test_error_diffs.py index 2bc58e0de..c879a707c 100644 --- a/testing/test_error_diffs.py +++ b/testing/test_error_diffs.py @@ -272,7 +272,7 @@ TESTCASES = [ """, """ > assert result == desired - E AssertionError: assert 'spam bacon\\n eggs love' == 'spam bacon eggs love' + E AssertionError: assert 'spam\\tbacon\\n\\teggs love' == 'spam bacon eggs love' E - spam bacon eggs love E + spam bacon E + eggs love From 75e3cc41efe845a9036edcd6488c6c7880bbb75d Mon Sep 17 00:00:00 2001 From: Maddie Thai-Tang Date: Tue, 2 May 2023 17:10:21 -0400 Subject: [PATCH 3/8] added tab printing in diff messages --- src/_pytest/assertion/util.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/_pytest/assertion/util.py b/src/_pytest/assertion/util.py index fc5dfdbd5..5a7b06a6a 100644 --- a/src/_pytest/assertion/util.py +++ b/src/_pytest/assertion/util.py @@ -289,6 +289,8 @@ 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)): + explanation[i] = explanation[i].replace(" ", "\t") return explanation From e2e9f7d12c555cac7c627758188e52ae447568c1 Mon Sep 17 00:00:00 2001 From: Maddie Thai-Tang Date: Wed, 3 May 2023 10:40:05 -0400 Subject: [PATCH 4/8] passing new test, need to fix other tests --- src/_pytest/assertion/util.py | 3 +++ testing/test_error_diffs.py | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/_pytest/assertion/util.py b/src/_pytest/assertion/util.py index 5a7b06a6a..672d858a2 100644 --- a/src/_pytest/assertion/util.py +++ b/src/_pytest/assertion/util.py @@ -290,7 +290,10 @@ def _diff_text(left: str, right: str, verbose: int = 0) -> List[str]: for line in ndiff(right.splitlines(keepends), left.splitlines(keepends)) ] for i in range(len(explanation)): + explanation[i] = explanation[i].replace("+ ", "+ \t") explanation[i] = explanation[i].replace(" ", "\t") + print("**********************LOOK HERE***********************") + print(explanation) return explanation diff --git a/testing/test_error_diffs.py b/testing/test_error_diffs.py index c879a707c..a12aac342 100644 --- a/testing/test_error_diffs.py +++ b/testing/test_error_diffs.py @@ -272,10 +272,10 @@ TESTCASES = [ """, """ > assert result == desired - E AssertionError: assert 'spam\\tbacon\\n\\teggs love' == 'spam bacon eggs love' + E AssertionError: assert 'spam bacon\\n eggs love' == 'spam bacon eggs love' E - spam bacon eggs love - E + spam bacon - E + eggs love + E + spam\tbacon + E + \teggs love """, id='Test "not in" string', ), From f55cec360461ff1fa856b02ce3e40455b9f4e488 Mon Sep 17 00:00:00 2001 From: Maddie Thai-Tang Date: Wed, 3 May 2023 11:11:04 -0400 Subject: [PATCH 5/8] finished issue, added changelog and names to authors file --- AUTHORS | 2 ++ changelog/10704.improvement.rst | 1 + src/_pytest/assertion/util.py | 7 +++---- 3 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 changelog/10704.improvement.rst diff --git a/AUTHORS b/AUTHORS index dee73514a..a68b548d3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -120,6 +120,7 @@ Eduardo Schettino Eli Boyarski Elizaveta Shashkova Éloi Rivard +Emmeline Wetzel Endre Galaczi Eric Hunsberger Eric Liu @@ -219,6 +220,7 @@ Loic Esteve Lukas Bednar Luke Murphy Maciek Fijalkowski +Madeline Thai-Tang Maho Maik Figura Mandeep Bhutani diff --git a/changelog/10704.improvement.rst b/changelog/10704.improvement.rst new file mode 100644 index 000000000..657fdfce6 --- /dev/null +++ b/changelog/10704.improvement.rst @@ -0,0 +1 @@ +Changed the diff explanation for string comparison assertions when there is a tab in the string to show ``\t`` instead of `` `` diff --git a/src/_pytest/assertion/util.py b/src/_pytest/assertion/util.py index 672d858a2..514bc8e17 100644 --- a/src/_pytest/assertion/util.py +++ b/src/_pytest/assertion/util.py @@ -290,10 +290,9 @@ def _diff_text(left: str, right: str, verbose: int = 0) -> List[str]: for line in ndiff(right.splitlines(keepends), left.splitlines(keepends)) ] for i in range(len(explanation)): - explanation[i] = explanation[i].replace("+ ", "+ \t") - explanation[i] = explanation[i].replace(" ", "\t") - print("**********************LOOK HERE***********************") - print(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 From 0b8c3de7a1a5feb3e9f50b88c71a7180f1c9d136 Mon Sep 17 00:00:00 2001 From: Maddie Thai-Tang Date: Wed, 3 May 2023 11:15:19 -0400 Subject: [PATCH 6/8] fixed changelog statement --- changelog/10704.improvement.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/10704.improvement.rst b/changelog/10704.improvement.rst index 657fdfce6..81978807c 100644 --- a/changelog/10704.improvement.rst +++ b/changelog/10704.improvement.rst @@ -1 +1 @@ -Changed the diff explanation for string comparison assertions when there is a tab in the string to show ``\t`` instead of `` `` +Changed the diff explanation for string comparison assertions when there is a tab in the string to show ``\t`` instead of four spaces. From 042bc2dd2e1c1b0b8cf8e84967019afea05c598b Mon Sep 17 00:00:00 2001 From: Maddie Thai-Tang Date: Wed, 3 May 2023 11:23:29 -0400 Subject: [PATCH 7/8] fixed tab to show repr --- src/_pytest/assertion/util.py | 4 ++-- testing/test_error_diffs.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/_pytest/assertion/util.py b/src/_pytest/assertion/util.py index 514bc8e17..99b7e1ae6 100644 --- a/src/_pytest/assertion/util.py +++ b/src/_pytest/assertion/util.py @@ -291,8 +291,8 @@ def _diff_text(left: str, right: str, verbose: int = 0) -> List[str]: ] 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") + explanation[i] = explanation[i].replace("+ ", "+ \\t") + explanation[i] = explanation[i].replace(" ", "\\t") return explanation diff --git a/testing/test_error_diffs.py b/testing/test_error_diffs.py index a12aac342..a0efb1294 100644 --- a/testing/test_error_diffs.py +++ b/testing/test_error_diffs.py @@ -274,8 +274,8 @@ TESTCASES = [ > 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 + E + spam\\tbacon + E + \\teggs love """, id='Test "not in" string', ), From 7e05578cb227bd84803b897d4938c1e5db5a7c50 Mon Sep 17 00:00:00 2001 From: Maddie Thai-Tang Date: Sat, 6 May 2023 16:44:24 -0400 Subject: [PATCH 8/8] fixed test id --- testing/test_error_diffs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/test_error_diffs.py b/testing/test_error_diffs.py index a0efb1294..7daf0eb47 100644 --- a/testing/test_error_diffs.py +++ b/testing/test_error_diffs.py @@ -277,7 +277,7 @@ TESTCASES = [ E + spam\\tbacon E + \\teggs love """, - id='Test "not in" string', + id="Test tab repr in diff", ), ]