From 990efe0fff749773887a50cb1ecb2c5d09263cf8 Mon Sep 17 00:00:00 2001 From: Lysandros Nikolaou Date: Mon, 29 Jun 2020 15:55:57 +0300 Subject: [3.9] bpo-41084: Fix test_fstring failure when using the old parser (GH-21212) --- Lib/test/test_fstring.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py index 5c27b73..e0812d1 100644 --- a/Lib/test/test_fstring.py +++ b/Lib/test/test_fstring.py @@ -524,7 +524,8 @@ non-important content # This looks like a nested format spec. ]) - self.assertAllRaise(SyntaxError, "f-string: invalid syntax", + err_msg = "invalid syntax" if use_old_parser() else "f-string: invalid syntax" + self.assertAllRaise(SyntaxError, err_msg, [# Invalid syntax inside a nested spec. "f'{4:{/5}}'", ]) @@ -598,7 +599,8 @@ non-important content # are added around it. But we shouldn't go from an invalid # expression to a valid one. The added parens are just # supposed to allow whitespace (including newlines). - self.assertAllRaise(SyntaxError, 'f-string: invalid syntax', + err_msg = "invalid syntax" if use_old_parser() else "f-string: invalid syntax" + self.assertAllRaise(SyntaxError, err_msg, ["f'{,}'", "f'{,}'", # this is (,), which is an error ]) @@ -716,7 +718,8 @@ non-important content # lambda doesn't work without parens, because the colon # makes the parser think it's a format_spec - self.assertAllRaise(SyntaxError, 'f-string: invalid syntax', + err_msg = "invalid syntax" if use_old_parser() else "f-string: invalid syntax" + self.assertAllRaise(SyntaxError, err_msg, ["f'{lambda x:x}'", ]) @@ -1201,7 +1204,8 @@ non-important content self.assertEqual(x, 10) def test_invalid_syntax_error_message(self): - with self.assertRaisesRegex(SyntaxError, "f-string: invalid syntax"): + err_msg = "invalid syntax" if use_old_parser() else "f-string: invalid syntax" + with self.assertRaisesRegex(SyntaxError, err_msg): compile("f'{a $ b}'", "?", "exec") -- cgit v0.12