diff options
author | han-solo <hanish0019@gmail.com> | 2020-09-01 14:34:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-01 14:34:29 (GMT) |
commit | 0d6aa7f0ee38eb453bc8f73bf4830e6172be2f35 (patch) | |
tree | 514106377b382e93d955fedc230dcc6e3a36cfff /Lib/test/test_fstring.py | |
parent | f5a16b4dbf62cb9b48c42098bd5a8cfa665456c3 (diff) | |
download | cpython-0d6aa7f0ee38eb453bc8f73bf4830e6172be2f35.zip cpython-0d6aa7f0ee38eb453bc8f73bf4830e6172be2f35.tar.gz cpython-0d6aa7f0ee38eb453bc8f73bf4830e6172be2f35.tar.bz2 |
bpo-41681: Fix for `f-string/str.format` error description when using 2 `,` in format specifier (GH-22036)
* Fixed `f-string/str.format` error description when using two `,` in format specifier.
Co-authored-by: millefalcon <hanish0019@hmail.com>
Diffstat (limited to 'Lib/test/test_fstring.py')
-rw-r--r-- | Lib/test/test_fstring.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py index 35a62a0..b9bede0 100644 --- a/Lib/test/test_fstring.py +++ b/Lib/test/test_fstring.py @@ -9,6 +9,7 @@ import ast import os +import re import types import decimal import unittest @@ -1198,6 +1199,25 @@ non-important content with self.assertRaisesRegex(SyntaxError, "f-string: invalid syntax"): compile("f'{a $ b}'", "?", "exec") + def test_with_two_commas_in_format_specifier(self): + error_msg = re.escape("Cannot specify ',' with ','.") + with self.assertRaisesRegex(ValueError, error_msg): + f'{1:,,}' + + def test_with_two_underscore_in_format_specifier(self): + error_msg = re.escape("Cannot specify '_' with '_'.") + with self.assertRaisesRegex(ValueError, error_msg): + f'{1:__}' + + def test_with_a_commas_and_an_underscore_in_format_specifier(self): + error_msg = re.escape("Cannot specify both ',' and '_'.") + with self.assertRaisesRegex(ValueError, error_msg): + f'{1:,_}' + + def test_with_an_underscore_and_a_comma_in_format_specifier(self): + error_msg = re.escape("Cannot specify both ',' and '_'.") + with self.assertRaisesRegex(ValueError, error_msg): + f'{1:,_}' if __name__ == '__main__': unittest.main() |