]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-115931: Fix `SyntaxWarning`s in `test_unparse` (GH-115935) (#115948)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 26 Feb 2024 13:00:14 +0000 (14:00 +0100)
committerGitHub <noreply@github.com>
Mon, 26 Feb 2024 13:00:14 +0000 (13:00 +0000)
gh-115931: Fix `SyntaxWarning`s in `test_unparse` (GH-115935)
(cherry picked from commit b7383b8b71d49c761480ae9a8b2111644310e61d)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Lib/test/test_unparse.py

index 77ce18cbf4cbfb5e03ba4ceeaa129c10b78562ae..106704ba8c9c2ddb84db7fd0c852b4d302fad471 100644 (file)
@@ -650,9 +650,18 @@ class CosmeticTestCase(ASTTestCase):
         self.check_ast_roundtrip("""f'''""\"''\\'{""\"\\n\\"'''""\" '''\\n'''}''' """)
 
     def test_backslash_in_format_spec(self):
-        self.check_ast_roundtrip("""f"{x:\\ }" """)
+        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:\\\\ }" """)
-        self.check_ast_roundtrip("""f"{x:\\\\\\ }" """)
+
+        with self.assertWarnsRegex(SyntaxWarning, msg):
+            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):