mirror of
https://github.com/python/cpython.git
synced 2025-10-06 23:21:06 +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
|
@ -2,6 +2,8 @@ import sys
|
|||
|
||||
import unittest
|
||||
from test import support
|
||||
from test.test_grammar import (VALID_UNDERSCORE_LITERALS,
|
||||
INVALID_UNDERSCORE_LITERALS)
|
||||
|
||||
L = [
|
||||
('0', 0),
|
||||
|
@ -212,6 +214,25 @@ class IntTestCases(unittest.TestCase):
|
|||
self.assertEqual(int('2br45qc', 35), 4294967297)
|
||||
self.assertEqual(int('1z141z5', 36), 4294967297)
|
||||
|
||||
def test_underscores(self):
|
||||
for lit in VALID_UNDERSCORE_LITERALS:
|
||||
if any(ch in lit for ch in '.eEjJ'):
|
||||
continue
|
||||
self.assertEqual(int(lit, 0), eval(lit))
|
||||
self.assertEqual(int(lit, 0), int(lit.replace('_', ''), 0))
|
||||
for lit in INVALID_UNDERSCORE_LITERALS:
|
||||
if any(ch in lit for ch in '.eEjJ'):
|
||||
continue
|
||||
self.assertRaises(ValueError, int, lit, 0)
|
||||
# Additional test cases with bases != 0, only for the constructor:
|
||||
self.assertEqual(int("1_00", 3), 9)
|
||||
self.assertEqual(int("0_100"), 100) # not valid as a literal!
|
||||
self.assertEqual(int(b"1_00"), 100) # byte underscore
|
||||
self.assertRaises(ValueError, int, "_100")
|
||||
self.assertRaises(ValueError, int, "+_100")
|
||||
self.assertRaises(ValueError, int, "1__00")
|
||||
self.assertRaises(ValueError, int, "100_")
|
||||
|
||||
@support.cpython_only
|
||||
def test_small_ints(self):
|
||||
# Bug #3236: Return small longs from PyLong_FromString
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue