From 2d029a5c5381b240acd59a7aa137e008aab6ed9a Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sat, 21 Oct 2023 11:55:41 +0300 Subject: [PATCH 1/4] gh-111155: Fix direct invocation of `test_pprint` --- Lib/test/test_pprint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_pprint.py b/Lib/test/test_pprint.py index 6ea7e7db2ce1132..c4873a5ad9665aa 100644 --- a/Lib/test/test_pprint.py +++ b/Lib/test/test_pprint.py @@ -535,7 +535,7 @@ def test_dataclass_with_repr(self): def test_dataclass_no_repr(self): dc = dataclass3() formatted = pprint.pformat(dc, width=10) - self.assertRegex(formatted, r"") + self.assertRegex(formatted, rf"<{__name__}.dataclass3 object at \w+>") def test_recursive_dataclass(self): dc = dataclass4(None) From 6d22cb3a4e8c53382cecbb83ee552f72622aa631 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sat, 21 Oct 2023 12:21:16 +0300 Subject: [PATCH 2/4] Address review --- Lib/test/test_pprint.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_pprint.py b/Lib/test/test_pprint.py index c4873a5ad9665aa..4ec47c4f24e610f 100644 --- a/Lib/test/test_pprint.py +++ b/Lib/test/test_pprint.py @@ -533,9 +533,11 @@ def test_dataclass_with_repr(self): self.assertEqual(formatted, "custom repr that doesn't fit within pprint width") def test_dataclass_no_repr(self): + import re + dc = dataclass3() formatted = pprint.pformat(dc, width=10) - self.assertRegex(formatted, rf"<{__name__}.dataclass3 object at \w+>") + self.assertRegex(formatted, re.escape(rf"<{__name__}.dataclass3 object at \w+>")) def test_recursive_dataclass(self): dc = dataclass4(None) From 03854e619523178c4cb433aba06d5ab04190b944 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sat, 21 Oct 2023 12:24:55 +0300 Subject: [PATCH 3/4] Address review --- Lib/test/test_pprint.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_pprint.py b/Lib/test/test_pprint.py index 4ec47c4f24e610f..7d9f7df54d81f62 100644 --- a/Lib/test/test_pprint.py +++ b/Lib/test/test_pprint.py @@ -537,7 +537,10 @@ def test_dataclass_no_repr(self): dc = dataclass3() formatted = pprint.pformat(dc, width=10) - self.assertRegex(formatted, re.escape(rf"<{__name__}.dataclass3 object at \w+>")) + self.assertRegex( + formatted, + re.escape(f"<{__name__}.dataclass3 object at ") + r"\w+>", + ) def test_recursive_dataclass(self): dc = dataclass4(None) From 47c99daf22bfbbf9f75bc0d036445419881ab6af Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sat, 21 Oct 2023 14:38:07 +0300 Subject: [PATCH 4/4] Address review --- Lib/test/test_pprint.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_pprint.py b/Lib/test/test_pprint.py index 7d9f7df54d81f62..4d1766fb16ce9fa 100644 --- a/Lib/test/test_pprint.py +++ b/Lib/test/test_pprint.py @@ -7,6 +7,7 @@ import itertools import pprint import random +import re import test.support import test.test_set import types @@ -533,13 +534,11 @@ def test_dataclass_with_repr(self): self.assertEqual(formatted, "custom repr that doesn't fit within pprint width") def test_dataclass_no_repr(self): - import re - dc = dataclass3() formatted = pprint.pformat(dc, width=10) self.assertRegex( formatted, - re.escape(f"<{__name__}.dataclass3 object at ") + r"\w+>", + fr"<{re.escape(__name__)}.dataclass3 object at \w+>", ) def test_recursive_dataclass(self):