gh-104089: catch DeprecationWarning in test_fstring (#104137)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
sunmy2019 2023-05-04 18:20:20 +08:00 committed by GitHub
parent 6ab463684b
commit 83751bbd14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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')