diff options
author | Mark Dickinson <mdickinson@enthought.com> | 2012-10-28 10:18:03 (GMT) |
---|---|---|
committer | Mark Dickinson <mdickinson@enthought.com> | 2012-10-28 10:18:03 (GMT) |
commit | fb90c0934c22041cad1fc4019c9853205befc967 (patch) | |
tree | 8814d98ae8a6cc931232a07790c55c40072aaccb /Lib/test/test_unicode.py | |
parent | 579d5cd643d31b732e6e7707582276565e44ece9 (diff) | |
download | cpython-fb90c0934c22041cad1fc4019c9853205befc967.zip cpython-fb90c0934c22041cad1fc4019c9853205befc967.tar.gz cpython-fb90c0934c22041cad1fc4019c9853205befc967.tar.bz2 |
Issue #14700: Fix buggy overflow checks for large precision and width in new-style and old-style formatting.
Diffstat (limited to 'Lib/test/test_unicode.py')
-rw-r--r-- | Lib/test/test_unicode.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 19b06a0..000ae6a 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -906,6 +906,21 @@ class UnicodeTest(string_tests.CommonTest, self.assertRaises(ValueError, '{}'.format_map, 'a') self.assertRaises(ValueError, '{a} {}'.format_map, {"a" : 2, "b" : 1}) + def test_format_huge_precision(self): + format_string = ".{}f".format(sys.maxsize + 1) + with self.assertRaises(ValueError): + result = format(2.34, format_string) + + def test_format_huge_width(self): + format_string = "{}f".format(sys.maxsize + 1) + with self.assertRaises(ValueError): + result = format(2.34, format_string) + + def test_format_huge_item_number(self): + format_string = "{{{}:.6f}}".format(sys.maxsize + 1) + with self.assertRaises(ValueError): + result = format_string.format(2.34) + def test_format_auto_numbering(self): class C: def __init__(self, x=100): @@ -990,6 +1005,18 @@ class UnicodeTest(string_tests.CommonTest, self.assertEqual('%f' % INF, 'inf') self.assertEqual('%F' % INF, 'INF') + @support.cpython_only + def test_formatting_huge_precision(self): + from _testcapi import INT_MAX + format_string = "%.{}f".format(INT_MAX + 1) + with self.assertRaises(ValueError): + result = format_string % 2.34 + + def test_formatting_huge_width(self): + format_string = "%{}f".format(sys.maxsize + 1) + with self.assertRaises(ValueError): + result = format_string % 2.34 + def test_startswith_endswith_errors(self): for meth in ('foo'.startswith, 'foo'.endswith): with self.assertRaises(TypeError) as cm: |