Mercurial > cpython-lru_cache-weakref
diff Lib/test/test_long.py @ 45023:727cc810d690
Restrict format presentation types to those specified in the 'Standard Format Specifiers' section of PEP 3101.
| author | Eric Smith <eric@trueblade.com> |
|---|---|
| date | Sun, 27 Jan 2008 21:07:59 +0000 |
| parents | 357b365560f4 |
| children | a28d0b14b77d |
line wrap: on
line diff
--- a/Lib/test/test_long.py Sun Jan 27 18:55:54 2008 +0000 +++ b/Lib/test/test_long.py Sun Jan 27 21:07:59 2008 +0000 @@ -526,16 +526,21 @@ self.assertEqual(format(1234, "+b"), "+10011010010") self.assertEqual(format(-1234, "+b"), "-10011010010") - # conversion to float - self.assertEqual(format(0, 'f'), '0.000000') - # make sure these are errors self.assertRaises(ValueError, format, 3, "1.3") # precision disallowed self.assertRaises(ValueError, format, 3, "+c") # sign not allowed # with 'c' - self.assertRaises(ValueError, format, 3, "R") # bogus format type - # conversion to string should fail - self.assertRaises(ValueError, format, 3, "s") + # other format specifiers shouldn't work on ints, + # in particular float and string specifiers + for format_spec in ([chr(x) for x in range(ord('a'), ord('z')+1)] + + [chr(x) for x in range(ord('A'), ord('Z')+1)]): + if not format_spec in 'bcdoxX': + self.assertRaises(ValueError, format, 0, format_spec) + self.assertRaises(ValueError, format, 1, format_spec) + self.assertRaises(ValueError, format, -1, format_spec) + self.assertRaises(ValueError, format, 2**100, format_spec) + self.assertRaises(ValueError, format, -(2**100), format_spec) + def test_nan_inf(self): self.assertRaises(OverflowError, int, float('inf'))
