From ddebda8c3a57ad7454980a7214cb56f24872c49d Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 26 Feb 2024 10:36:12 +0300 Subject: [PATCH 1/2] gh-115931: Fix `SyntaxWarning`s in `test_unparse` --- Lib/test/test_unparse.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_unparse.py b/Lib/test/test_unparse.py index 77ce18cbf4cbfb5..78681752e82540b 100644 --- a/Lib/test/test_unparse.py +++ b/Lib/test/test_unparse.py @@ -650,9 +650,16 @@ def test_multiquote_joined_string(self): self.check_ast_roundtrip("""f'''""\"''\\'{""\"\\n\\"'''""\" '''\\n'''}''' """) def test_backslash_in_format_spec(self): - self.check_ast_roundtrip("""f"{x:\\ }" """) + with self.assertWarns(SyntaxWarning): + self.check_ast_roundtrip("""f"{x:\\ }" """) + self.check_ast_roundtrip("""f"{x:\\n}" """) + self.check_ast_roundtrip("""f"{x:\\\\ }" """) - self.check_ast_roundtrip("""f"{x:\\\\\\ }" """) + + with self.assertWarns(SyntaxWarning): + self.check_ast_roundtrip("""f"{x:\\\\\\ }" """) + self.check_ast_roundtrip("""f"{x:\\\\\\n}" """) + self.check_ast_roundtrip("""f"{x:\\\\\\\\ }" """) def test_quote_in_format_spec(self): From e3280be2549ee7296d22ad4c8d529e7e1002f4f7 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 26 Feb 2024 11:51:13 +0300 Subject: [PATCH 2/2] Address review --- Lib/test/test_unparse.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_unparse.py b/Lib/test/test_unparse.py index 78681752e82540b..106704ba8c9c2dd 100644 --- a/Lib/test/test_unparse.py +++ b/Lib/test/test_unparse.py @@ -650,13 +650,15 @@ def test_multiquote_joined_string(self): self.check_ast_roundtrip("""f'''""\"''\\'{""\"\\n\\"'''""\" '''\\n'''}''' """) def test_backslash_in_format_spec(self): - with self.assertWarns(SyntaxWarning): + import re + msg = re.escape("invalid escape sequence '\\ '") + with self.assertWarnsRegex(SyntaxWarning, msg): self.check_ast_roundtrip("""f"{x:\\ }" """) self.check_ast_roundtrip("""f"{x:\\n}" """) self.check_ast_roundtrip("""f"{x:\\\\ }" """) - with self.assertWarns(SyntaxWarning): + with self.assertWarnsRegex(SyntaxWarning, msg): self.check_ast_roundtrip("""f"{x:\\\\\\ }" """) self.check_ast_roundtrip("""f"{x:\\\\\\n}" """)