summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_float.py
diff options
context:
space:
mode:
authorEric Smith <eric@trueblade.com>2008-01-27 21:07:59 (GMT)
committerEric Smith <eric@trueblade.com>2008-01-27 21:07:59 (GMT)
commit7b69c6c3afba79518865313e1b41845a6b534fb6 (patch)
tree1a2f2f8e142378ff212cc4f57083e8a983cbe297 /Lib/test/test_float.py
parent412dc9c88f040abf4b23017c5e5e4d8b880d247d (diff)
downloadcpython-7b69c6c3afba79518865313e1b41845a6b534fb6.zip
cpython-7b69c6c3afba79518865313e1b41845a6b534fb6.tar.gz
cpython-7b69c6c3afba79518865313e1b41845a6b534fb6.tar.bz2
Restrict format presentation types to those specified in the 'Standard Format Specifiers' section of PEP 3101.
Diffstat (limited to 'Lib/test/test_float.py')
-rw-r--r--Lib/test/test_float.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py
index 0de65cb..b9ad8c5 100644
--- a/Lib/test/test_float.py
+++ b/Lib/test/test_float.py
@@ -133,13 +133,10 @@ class FormatTestCase(unittest.TestCase):
self.assertEqual(format(0.01, ''), '0.01')
self.assertEqual(format(0.01, 'g'), '0.01')
- self.assertEqual(format(0, 'f'), '0.000000')
self.assertEqual(format(1.0, 'f'), '1.000000')
- self.assertEqual(format(1, 'f'), '1.000000')
self.assertEqual(format(-1.0, 'f'), '-1.000000')
- self.assertEqual(format(-1, 'f'), '-1.000000')
self.assertEqual(format( 1.0, ' f'), ' 1.000000')
self.assertEqual(format(-1.0, ' f'), '-1.000000')
@@ -152,6 +149,18 @@ class FormatTestCase(unittest.TestCase):
# conversion to string should fail
self.assertRaises(ValueError, format, 3.0, "s")
+ # other format specifiers shouldn't work on floats,
+ # in particular int 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 'eEfFgGn%':
+ self.assertRaises(ValueError, format, 0.0, format_spec)
+ self.assertRaises(ValueError, format, 1.0, format_spec)
+ self.assertRaises(ValueError, format, -1.0, format_spec)
+ self.assertRaises(ValueError, format, 1e100, format_spec)
+ self.assertRaises(ValueError, format, -1e100, format_spec)
+ self.assertRaises(ValueError, format, 1e-100, format_spec)
+ self.assertRaises(ValueError, format, -1e-100, format_spec)
class ReprTestCase(unittest.TestCase):
def test_repr(self):