diff options
Diffstat (limited to 'Lib/test/test_complex.py')
-rw-r--r-- | Lib/test/test_complex.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py index 2810b36..cc21aa7 100644 --- a/Lib/test/test_complex.py +++ b/Lib/test/test_complex.py @@ -555,8 +555,28 @@ class ComplexTest(unittest.TestCase): self.assertEqual(format(1.5e21+3j, '^40,.2f'), ' 1,500,000,000,000,000,000,000.00+3.00j ') self.assertEqual(format(1.5e21+3000j, ',.2f'), '1,500,000,000,000,000,000,000.00+3,000.00j') - # alternate is invalid - self.assertRaises(ValueError, (1.5+0.5j).__format__, '#f') + # Issue 7094: Alternate formatting (specified by #) + self.assertEqual(format(1+1j, '.0e'), '1e+00+1e+00j') + self.assertEqual(format(1+1j, '#.0e'), '1.e+00+1.e+00j') + self.assertEqual(format(1+1j, '.0f'), '1+1j') + self.assertEqual(format(1+1j, '#.0f'), '1.+1.j') + self.assertEqual(format(1.1+1.1j, 'g'), '1.1+1.1j') + self.assertEqual(format(1.1+1.1j, '#g'), '1.10000+1.10000j') + + # Alternate doesn't make a difference for these, they format the same with or without it + self.assertEqual(format(1+1j, '.1e'), '1.0e+00+1.0e+00j') + self.assertEqual(format(1+1j, '#.1e'), '1.0e+00+1.0e+00j') + self.assertEqual(format(1+1j, '.1f'), '1.0+1.0j') + self.assertEqual(format(1+1j, '#.1f'), '1.0+1.0j') + + # Misc. other alternate tests + self.assertEqual(format((-1.5+0.5j), '#f'), '-1.500000+0.500000j') + self.assertEqual(format((-1.5+0.5j), '#.0f'), '-2.+0.j') + self.assertEqual(format((-1.5+0.5j), '#e'), '-1.500000e+00+5.000000e-01j') + self.assertEqual(format((-1.5+0.5j), '#.0e'), '-2.e+00+5.e-01j') + self.assertEqual(format((-1.5+0.5j), '#g'), '-1.50000+0.500000j') + self.assertEqual(format((-1.5+0.5j), '.0g'), '-2+0.5j') + self.assertEqual(format((-1.5+0.5j), '#.0g'), '-2.+0.5j') # zero padding is invalid self.assertRaises(ValueError, (1.5+0.5j).__format__, '010f') |