mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Issue #18137: Detect integer overflow on precision in float.__format__() and
complex.__format__().
This commit is contained in:
parent
da30acf50b
commit
2f084ecfe7
3 changed files with 34 additions and 2 deletions
|
@ -312,6 +312,23 @@ class FormatTest(unittest.TestCase):
|
|||
def test_main():
|
||||
support.run_unittest(FormatTest)
|
||||
|
||||
def test_precision(self):
|
||||
INT_MAX = 2147483647
|
||||
|
||||
f = 1.2
|
||||
self.assertEqual(format(f, ".0f"), "1")
|
||||
self.assertEqual(format(f, ".3f"), "1.200")
|
||||
with self.assertRaises(ValueError) as cm:
|
||||
format(f, ".%sf" % (INT_MAX + 1))
|
||||
self.assertEqual(str(cm.exception), "precision too big")
|
||||
|
||||
c = complex(f)
|
||||
self.assertEqual(format(f, ".0f"), "1")
|
||||
self.assertEqual(format(f, ".3f"), "1.200")
|
||||
with self.assertRaises(ValueError) as cm:
|
||||
format(f, ".%sf" % (INT_MAX + 1))
|
||||
self.assertEqual(str(cm.exception), "precision too big")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue