Skip to content

Commit 94bd220

Browse files
committed
gh-110131: Test argparse's extend action with a non-empty default
TestOptionalsActionAppendWithDefault covers this for 'append'; there was no equivalent for 'extend', so nothing pinned the behavior the docs now describe. The coverage is limited to an option, matching the scope of the new sentence.
1 parent 93406f1 commit 94bd220

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

‎Lib/test/test_argparse.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,6 +2470,21 @@ class TestActionExtend(ParserTestCase):
24702470
]
24712471

24722472

2473+
class TestActionExtendWithDefault(ParserTestCase):
2474+
"""Tests the extend action for an Optional with a non-empty default"""
2475+
2476+
argument_signatures = [
2477+
Sig('--baz', action='extend', nargs='+', default=['X']),
2478+
]
2479+
failures = ['a', '--baz', 'a --baz']
2480+
successes = [
2481+
('', NS(baz=['X'])),
2482+
('--baz a', NS(baz=['X', 'a'])),
2483+
('--baz a b', NS(baz=['X', 'a', 'b'])),
2484+
('--baz a --baz b c', NS(baz=['X', 'a', 'b', 'c'])),
2485+
]
2486+
2487+
24732488
class TestNegativeNumber(ParserTestCase):
24742489
"""Test parsing negative numbers"""
24752490

0 commit comments

Comments
 (0)