]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-115931: Fix `SyntaxWarning`s in `test_unparse` (#115935)
authorNikita Sobolev <mail@sobolevn.me>
Mon, 26 Feb 2024 12:32:27 +0000 (15:32 +0300)
committerGitHub <noreply@github.com>
Mon, 26 Feb 2024 12:32:27 +0000 (13:32 +0100)
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):