summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2024-02-26 12:32:27 (GMT)
committerGitHub <noreply@github.com>2024-02-26 12:32:27 (GMT)
commitb7383b8b71d49c761480ae9a8b2111644310e61d (patch)
tree48f26708300a4ba6f868d5fce1c8d0cfa9aabb86
parent37f5d06b1bf830048c09ed967bb2cda945d56541 (diff)
downloadcpython-b7383b8b71d49c761480ae9a8b2111644310e61d.zip
cpython-b7383b8b71d49c761480ae9a8b2111644310e61d.tar.gz
cpython-b7383b8b71d49c761480ae9a8b2111644310e61d.tar.bz2
gh-115931: Fix `SyntaxWarning`s in `test_unparse` (#115935)
-rw-r--r--Lib/test/test_unparse.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/Lib/test/test_unparse.py b/Lib/test/test_unparse.py
index 77ce18c..106704b 100644
--- a/Lib/test/test_unparse.py
+++ b/Lib/test/test_unparse.py
@@ -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):