diff options
author | Eric Smith <eric@trueblade.com> | 2008-01-28 10:59:27 (GMT) |
---|---|---|
committer | Eric Smith <eric@trueblade.com> | 2008-01-28 10:59:27 (GMT) |
commit | fa767efe0662c7927e644747fa08c083f01b0653 (patch) | |
tree | 2c2ba9c96d8674069386f8c854b6c73776c3e5b1 /Lib/test/test_long.py | |
parent | fe82e774ea203de277968216126e26d0d09b3a15 (diff) | |
download | cpython-fa767efe0662c7927e644747fa08c083f01b0653.zip cpython-fa767efe0662c7927e644747fa08c083f01b0653.tar.gz cpython-fa767efe0662c7927e644747fa08c083f01b0653.tar.bz2 |
Partially revert r60376: restore ability for ints to be automatically converted to floats, if a float type specifier is given to an int. PEP 3101 should be clarified on this point.Also, remove unused local variables left over from r60376.
Diffstat (limited to 'Lib/test/test_long.py')
-rw-r--r-- | Lib/test/test_long.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py index 2c9e2d0..8eb09d1 100644 --- a/Lib/test/test_long.py +++ b/Lib/test/test_long.py @@ -530,17 +530,23 @@ class LongTest(unittest.TestCase): self.assertRaises(ValueError, format, 3, "1.3") # precision disallowed self.assertRaises(ValueError, format, 3, "+c") # sign not allowed # with 'c' - # other format specifiers shouldn't work on ints, - # in particular float and string specifiers + + # ensure that only int and float type specifiers work 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': + if not format_spec in 'bcdoxXeEfFgGn%': 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) + # ensure that float type specifiers work; format converts + # the int to a float + for format_spec in 'eEfFgGn%': + for value in [0, 1, -1, 100, -100, 1234567890, -1234567890]: + self.assertEqual(format(value, format_spec), + format(float(value), format_spec)) def test_nan_inf(self): self.assertRaises(OverflowError, int, float('inf')) |