[3.12] gh-115931: Fix SyntaxWarnings in test_unparse (GH-115935) (#115948)

gh-115931: Fix `SyntaxWarning`s in `test_unparse` (GH-115935)
(cherry picked from commit b7383b8b71)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
Miss Islington (bot) 2024-02-26 14:00:14 +01:00 committed by GitHub
parent 79061af448
commit 8668b3cc2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View 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):