diff options
author | Mark Dickinson <mdickinson@enthought.com> | 2012-10-28 10:00:46 +0000 |
---|---|---|
committer | Mark Dickinson <mdickinson@enthought.com> | 2012-10-28 10:00:46 +0000 |
commit | 75d36004665a637c5d0aa868a5d0b728b3d03d39 (patch) | |
tree | eaae340a81386d4ca660f446cd69f586bf7b10a9 /Lib/test/test_str.py | |
parent | 08114d40e94fa97ac9a55b80b69dc269da904fcc (diff) | |
download | cpython-git-75d36004665a637c5d0aa868a5d0b728b3d03d39.tar.gz |
Issue #14700: Fix buggy overflow checks for large precision and width in new-style and old-style formatting.
Diffstat (limited to 'Lib/test/test_str.py')
-rw-r--r-- | Lib/test/test_str.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_str.py b/Lib/test/test_str.py index 2ecf3276b4..eb704ead4f 100644 --- a/Lib/test/test_str.py +++ b/Lib/test/test_str.py @@ -35,6 +35,18 @@ class StrTest( string_tests.MixinStrUnicodeUserStringTest.test_formatting(self) self.assertRaises(OverflowError, '%c'.__mod__, 0x1234) + @test_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_conversion(self): # Make sure __str__() behaves properly class Foo0: @@ -371,6 +383,21 @@ class StrTest( self.assertRaises(ValueError, format, "", "-") self.assertRaises(ValueError, "{0:=s}".format, '') + 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): |