@@ -981,6 +981,21 @@ def __format__(self, spec):
981
981
self .assertRaises (ValueError , '{}' .format_map , 'a' )
982
982
self .assertRaises (ValueError , '{a} {}' .format_map , {"a" : 2 , "b" : 1 })
983
983
984
+ def test_format_huge_precision (self ):
985
+ format_string = ".{}f" .format (sys .maxsize + 1 )
986
+ with self .assertRaises (ValueError ):
987
+ result = format (2.34 , format_string )
988
+
989
+ def test_format_huge_width (self ):
990
+ format_string = "{}f" .format (sys .maxsize + 1 )
991
+ with self .assertRaises (ValueError ):
992
+ result = format (2.34 , format_string )
993
+
994
+ def test_format_huge_item_number (self ):
995
+ format_string = "{{{}:.6f}}" .format (sys .maxsize + 1 )
996
+ with self .assertRaises (ValueError ):
997
+ result = format_string .format (2.34 )
998
+
984
999
def test_format_auto_numbering (self ):
985
1000
class C :
986
1001
def __init__ (self , x = 100 ):
@@ -1069,6 +1084,18 @@ def __str__(self):
1069
1084
self .assertEqual ('%.1s' % "a\xe9 \u20ac " , 'a' )
1070
1085
self .assertEqual ('%.2s' % "a\xe9 \u20ac " , 'a\xe9 ' )
1071
1086
1087
+ @support .cpython_only
1088
+ def test_formatting_huge_precision (self ):
1089
+ from _testcapi import INT_MAX
1090
+ format_string = "%.{}f" .format (INT_MAX + 1 )
1091
+ with self .assertRaises (ValueError ):
1092
+ result = format_string % 2.34
1093
+
1094
+ def test_formatting_huge_width (self ):
1095
+ format_string = "%{}f" .format (sys .maxsize + 1 )
1096
+ with self .assertRaises (ValueError ):
1097
+ result = format_string % 2.34
1098
+
1072
1099
def test_startswith_endswith_errors (self ):
1073
1100
for meth in ('foo' .startswith , 'foo' .endswith ):
1074
1101
with self .assertRaises (TypeError ) as cm :
0 commit comments