mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Restrict format presentation types to those specified in the 'Standard Format Specifiers' section of PEP 3101.
This commit is contained in:
parent
412dc9c88f
commit
7b69c6c3af
3 changed files with 23 additions and 86 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue