gh-115931: Fix SyntaxWarnings in test_unparse (#115935)

This commit is contained in:
Nikita Sobolev 2024-02-26 15:32:27 +03:00 committed by GitHub
parent 37f5d06b1b
commit b7383b8b71
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -650,9 +650,18 @@ 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:\\ }" """)
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):