From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Mon, 26 Feb 2024 13:00:14 +0000 (+0100) Subject: [3.12] gh-115931: Fix `SyntaxWarning`s in `test_unparse` (GH-115935) (#115948) X-Git-Tag: v3.12.3~200 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8668b3cc2d926250fb29738788df7da6a45d2278;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-115931: Fix `SyntaxWarning`s in `test_unparse` (GH-115935) (#115948) gh-115931: Fix `SyntaxWarning`s in `test_unparse` (GH-115935) (cherry picked from commit b7383b8b71d49c761480ae9a8b2111644310e61d) Co-authored-by: Nikita Sobolev --- diff --git a/Lib/test/test_unparse.py b/Lib/test/test_unparse.py index 77ce18cbf4cb..106704ba8c9c 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):