diff options
author | sunmy2019 <59365878+sunmy2019@users.noreply.github.com> | 2023-05-04 10:20:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-04 10:20:20 (GMT) |
commit | 83751bbd142c23ca3f6af34ec617630dc3173b2a (patch) | |
tree | 97c92ee4e7f788f71ffc7ec8a429033390fe4326 /Lib | |
parent | 6ab463684b9d79880d98cd1f1406aa86af65985e (diff) | |
download | cpython-83751bbd142c23ca3f6af34ec617630dc3173b2a.zip cpython-83751bbd142c23ca3f6af34ec617630dc3173b2a.tar.gz cpython-83751bbd142c23ca3f6af34ec617630dc3173b2a.tar.bz2 |
gh-104089: catch DeprecationWarning in `test_fstring` (#104137)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_fstring.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py index be71fde5..58e2550 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') |