summaryrefslogtreecommitdiff
path: root/tests/test_argparse_custom.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-07-15 16:29:06 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-07-15 16:29:06 -0400
commit218091f1ae3fd9ee0435fb126ea8e032ed3de76f (patch)
tree635d267f3a84ae84117e64416e16ad438642e6db /tests/test_argparse_custom.py
parent2e541a8a9a52ec23f5e337175314606ce2702381 (diff)
downloadcmd2-git-218091f1ae3fd9ee0435fb126ea8e032ed3de76f.tar.gz
Added ability to specify nargs ranges with no upper bound
Diffstat (limited to 'tests/test_argparse_custom.py')
-rw-r--r--tests/test_argparse_custom.py33
1 files changed, 15 insertions, 18 deletions
diff --git a/tests/test_argparse_custom.py b/tests/test_argparse_custom.py
index b738efa3..17fd8334 100644
--- a/tests/test_argparse_custom.py
+++ b/tests/test_argparse_custom.py
@@ -70,28 +70,20 @@ def test_apcustom_nargs_help_format(cust_app):
def test_apcustom_nargs_not_enough(cust_app):
out, err = run_cmd(cust_app, 'range --arg1 one')
- assert 'Error: argument --arg1: Expected between 2 and 3 arguments' in err[2]
+ assert 'Error: argument --arg1: expected 2 to 3 arguments' in err[2]
-def test_apcustom_narg_empty_tuple():
- with pytest.raises(ValueError) as excinfo:
- parser = cmd2.ArgParser(prog='test')
- parser.add_argument('invalid_tuple', nargs=())
- assert 'Ranged values for nargs must be a tuple of 2 integers' in str(excinfo.value)
-
-
-def test_apcustom_narg_single_tuple():
- with pytest.raises(ValueError) as excinfo:
- parser = cmd2.ArgParser(prog='test')
- parser.add_argument('invalid_tuple', nargs=(1,))
- assert 'Ranged values for nargs must be a tuple of 2 integers' in str(excinfo.value)
-
-
-def test_apcustom_narg_tuple_triple():
+@pytest.mark.parametrize('nargs_tuple', [
+ (),
+ ('f', 5),
+ (5, 'f'),
+ (1, 2, 3),
+])
+def test_apcustom_narg_invalid_tuples(nargs_tuple):
with pytest.raises(ValueError) as excinfo:
parser = cmd2.ArgParser(prog='test')
- parser.add_argument('invalid_tuple', nargs=(1, 2, 3))
- assert 'Ranged values for nargs must be a tuple of 2 integers' in str(excinfo.value)
+ parser.add_argument('invalid_tuple', nargs=nargs_tuple)
+ assert 'Ranged values for nargs must be a tuple of 1 or 2 integers' in str(excinfo.value)
def test_apcustom_narg_tuple_order():
@@ -113,6 +105,11 @@ def test_apcustom_narg_tuple_zero_base():
parser.add_argument('tuple', nargs=(0, 3))
+def test_apcustom_narg_single_tuple():
+ parser = cmd2.ArgParser(prog='test')
+ parser.add_argument('tuple', nargs=(5,))
+
+
def test_apcustom_narg_tuple_zero_to_one():
parser = cmd2.ArgParser(prog='test')
parser.add_argument('tuple', nargs=(0, 1))