summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_argparse_completer.py11
-rw-r--r--tests/test_argparse_custom.py33
2 files changed, 17 insertions, 27 deletions
diff --git a/tests/test_argparse_completer.py b/tests/test_argparse_completer.py
index 1262b9e1..4ad4c560 100644
--- a/tests/test_argparse_completer.py
+++ b/tests/test_argparse_completer.py
@@ -596,10 +596,7 @@ def test_unfinished_flag_error(ac_app, command_and_args, text, is_error, capsys)
complete_tester(text, line, begidx, endidx, ac_app)
out, err = capsys.readouterr()
- if is_error:
- assert "Flag requires" in out
- else:
- assert "Flag requires" not in out
+ assert is_error == all(x in out for x in ["Error:\n", "expected"])
def test_completion_items_default_header(ac_app):
@@ -651,11 +648,7 @@ def test_autocomp_hint(ac_app, command_and_args, text, has_hint, capsys):
complete_tester(text, line, begidx, endidx, ac_app)
out, err = capsys.readouterr()
-
- if has_hint:
- assert "Hint" in out
- else:
- assert "Hint" not in out
+ assert has_hint == ("Hint:\n" in out)
def test_autocomp_hint_multiple_lines(ac_app, capsys):
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))