GH-124693: Support parsing negative scientific and complex numbers argparse (GH-124823)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Savannah Ostrowski 2024-10-09 15:56:50 -06:00 committed by GitHub
parent 52f70da19c
commit 0c5a48c1c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 8 deletions

View file

@ -2195,20 +2195,33 @@ class TestNegativeNumber(ParserTestCase):
argument_signatures = [
Sig('--int', type=int),
Sig('--float', type=float),
Sig('--complex', type=complex),
]
failures = [
'--float -_.45',
'--float -1__000.0',
'--float -1.0.0',
'--int -1__000',
'--int -1.0',
'--complex -1__000.0j',
'--complex -1.0jj',
'--complex -_.45j',
]
successes = [
('--int -1000 --float -1000.0', NS(int=-1000, float=-1000.0)),
('--int -1_000 --float -1_000.0', NS(int=-1000, float=-1000.0)),
('--int -1_000_000 --float -1_000_000.0', NS(int=-1000000, float=-1000000.0)),
('--float -1_000.0', NS(int=None, float=-1000.0)),
('--float -1_000_000.0_0', NS(int=None, float=-1000000.0)),
('--float -.5', NS(int=None, float=-0.5)),
('--float -.5_000', NS(int=None, float=-0.5)),
('--int -1000 --float -1000.0', NS(int=-1000, float=-1000.0, complex=None)),
('--int -1_000 --float -1_000.0', NS(int=-1000, float=-1000.0, complex=None)),
('--int -1_000_000 --float -1_000_000.0', NS(int=-1000000, float=-1000000.0, complex=None)),
('--float -1_000.0', NS(int=None, float=-1000.0, complex=None)),
('--float -1_000_000.0_0', NS(int=None, float=-1000000.0, complex=None)),
('--float -.5', NS(int=None, float=-0.5, complex=None)),
('--float -.5_000', NS(int=None, float=-0.5, complex=None)),
('--float -1e3', NS(int=None, float=-1000, complex=None)),
('--float -1e-3', NS(int=None, float=-0.001, complex=None)),
('--complex -1j', NS(int=None, float=None, complex=-1j)),
('--complex -1_000j', NS(int=None, float=None, complex=-1000j)),
('--complex -1_000.0j', NS(int=None, float=None, complex=-1000.0j)),
('--complex -1e3j', NS(int=None, float=None, complex=-1000j)),
('--complex -1e-3j', NS(int=None, float=None, complex=-0.001j)),
]
class TestInvalidAction(TestCase):