8000 [3.12] gh-115931: Fix `SyntaxWarning`s in `test_unparse` (GH-115935) … · python/cpython@8668b3c · GitHub
[go: up one dir, main page]

Skip to content

Commit 8668b3c

Browse files
[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 b7383b8) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
1 parent 79061af commit 8668b3c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Lib/test/test_unparse.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,18 @@ def test_multiquote_joined_string(self):
650650
self.check_ast_roundtrip("""f'''""\"''\\'{""\"\\n\\"'''""\" '''\\n'''}''' """)
651651

652652
def test_backslash_in_format_spec(self):
653-
self.check_ast_roundtrip("""f"{x:\\ }" """)
653+
import re
654+
msg = re.escape("invalid escape sequence '\\ '")
655+
with self.assertWarnsRegex(SyntaxWarning, msg):
656+
self.check_ast_roundtrip("""f"{x:\\ }" """)
657+
self.check_ast_roundtrip("""f"{x:\\n}" """)
658+
654659
self.check_ast_roundtrip("""f"{x:\\\\ }" """)
655-
self.check_ast_roundtrip("""f"{x:\\\\\\ }" """)
660+
661+
with self.assertWarnsRegex(SyntaxWarning, msg):
662+
self.check_ast_roundtrip("""f"{x:\\\\\\ }" """)
663+
self.check_ast_roundtrip("""f"{x:\\\\\\n}" """)
664+
656665
self.check_ast_roundtrip("""f"{x:\\\\\\\\ }" """)
657666

658667
def test_quote_in_format_spec(self):

0 commit comments

Comments
 (0)
0