mirror of
https://github.com/python/cpython.git
synced 2024-11-23 18:04:37 +08:00
gh-104089: catch DeprecationWarning in test_fstring
(#104137)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
6ab463684b
commit
83751bbd14
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user