From: sunmy2019 <59365878+sunmy2019@users.noreply.github.com> Date: Thu, 4 May 2023 10:20:20 +0000 (+0800) Subject: gh-104089: catch DeprecationWarning in `test_fstring` (#104137) X-Git-Tag: v3.12.0b1~289 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=83751bbd142c23ca3f6af34ec617630dc3173b2a;p=thirdparty%2FPython%2Fcpython.git gh-104089: catch DeprecationWarning in `test_fstring` (#104137) Co-authored-by: Alex Waygood --- diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py index be71fde5aaba..58e2550715ce 100644 --- a/Lib/test/test_fstring.py +++ b/Lib/test/test_fstring.py @@ -980,11 +980,18 @@ x = ( self.assertEqual(fr'\"\'\"\'', '\\"\\\'\\"\\\'') def test_fstring_backslash_before_double_bracket(self): - self.assertEqual(f'\{{\}}', '\\{\\}') - self.assertEqual(f'\{{', '\\{') - self.assertEqual(f'\{{{1+1}', '\\{2') - self.assertEqual(f'\}}{1+1}', '\\}2') - self.assertEqual(f'{1+1}\}}', '2\\}') + deprecated_cases = [ + (r"f'\{{\}}'", '\\{\\}'), + (r"f'\{{'", '\\{'), + (r"f'\{{{1+1}'", '\\{2'), + (r"f'\}}{1+1}'", '\\}2'), + (r"f'{1+1}\}}'", '2\\}') + ] + for case, expected_result in deprecated_cases: + with self.subTest(case=case, expected_result=expected_result): + with self.assertWarns(DeprecationWarning): + result = eval(case) + self.assertEqual(result, expected_result) self.assertEqual(fr'\{{\}}', '\\{\\}') self.assertEqual(fr'\{{', '\\{') self.assertEqual(fr'\{{{1+1}', '\\{2')