mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Issue #26331: Implement the parsing part of PEP 515.
Thanks to Georg Brandl for the patch.
This commit is contained in:
parent
ee73a65745
commit
a721abac29
22 changed files with 743 additions and 205 deletions
|
@ -1,5 +1,7 @@
|
|||
import unittest
|
||||
from test import support
|
||||
from test.test_grammar import (VALID_UNDERSCORE_LITERALS,
|
||||
INVALID_UNDERSCORE_LITERALS)
|
||||
|
||||
from random import random
|
||||
from math import atan2, isnan, copysign
|
||||
|
@ -377,6 +379,18 @@ class ComplexTest(unittest.TestCase):
|
|||
self.assertAlmostEqual(complex(complex1(1j)), 2j)
|
||||
self.assertRaises(TypeError, complex, complex2(1j))
|
||||
|
||||
def test_underscores(self):
|
||||
# check underscores
|
||||
for lit in VALID_UNDERSCORE_LITERALS:
|
||||
if not any(ch in lit for ch in 'xXoObB'):
|
||||
self.assertEqual(complex(lit), eval(lit))
|
||||
self.assertEqual(complex(lit), complex(lit.replace('_', '')))
|
||||
for lit in INVALID_UNDERSCORE_LITERALS:
|
||||
if lit in ('0_7', '09_99'): # octals are not recognized here
|
||||
continue
|
||||
if not any(ch in lit for ch in 'xXoObB'):
|
||||
self.assertRaises(ValueError, complex, lit)
|
||||
|
||||
def test_hash(self):
|
||||
for x in range(-30, 30):
|
||||
self.assertEqual(hash(x), hash(complex(x, 0)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue