summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorsunmy2019 <59365878+sunmy2019@users.noreply.github.com>2023-05-04 10:20:20 (GMT)
committerGitHub <noreply@github.com>2023-05-04 10:20:20 (GMT)
commit83751bbd142c23ca3f6af34ec617630dc3173b2a (patch)
tree97c92ee4e7f788f71ffc7ec8a429033390fe4326 /Lib
parent6ab463684b9d79880d98cd1f1406aa86af65985e (diff)
downloadcpython-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.py17
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')