diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-06-23 12:55:43 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-06-23 12:55:43 (GMT) |
commit | 2ab07f01a4787336600b95cdf0312a9e6e00f34e (patch) | |
tree | e94f8996b44832e6a36078fd4eb40b39a63faea7 /Lib/test | |
parent | c6ebd16a203b84de020fb236f32e8c58db92718d (diff) | |
parent | 2f084ecfe78472b6a1a6c8b07472672176d4f848 (diff) | |
download | cpython-2ab07f01a4787336600b95cdf0312a9e6e00f34e.zip cpython-2ab07f01a4787336600b95cdf0312a9e6e00f34e.tar.gz cpython-2ab07f01a4787336600b95cdf0312a9e6e00f34e.tar.bz2 |
(Merge 3.3) Issue #18137: Detect integer overflow on precision in
float.__format__() and complex.__format__().
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_format.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py index bbce970..9f7630c 100644 --- a/Lib/test/test_format.py +++ b/Lib/test/test_format.py @@ -331,6 +331,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() |