summaryrefslogtreecommitdiff
path: root/tests/test_argparse_custom.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-07-05 16:58:35 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-07-05 16:58:35 -0400
commit655243cb6f586e33c68928f838fcd7d921da1101 (patch)
tree226b6b1d5cf4b45e023baa7df75f8a09d1f3be95 /tests/test_argparse_custom.py
parent1d560965bf5e03d82c4c353899ee9c7a6bf70a14 (diff)
downloadcmd2-git-655243cb6f586e33c68928f838fcd7d921da1101.tar.gz
Reorganized argparse completion and custom unit tests
Diffstat (limited to 'tests/test_argparse_custom.py')
-rw-r--r--tests/test_argparse_custom.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/test_argparse_custom.py b/tests/test_argparse_custom.py
new file mode 100644
index 00000000..85587d49
--- /dev/null
+++ b/tests/test_argparse_custom.py
@@ -0,0 +1,51 @@
+# flake8: noqa E302
+"""
+Unit/functional testing for argparse customizations in cmd2
+"""
+import pytest
+from cmd2.argparse_custom import Cmd2ArgParser
+
+
+def test_acarg_narg_empty_tuple():
+ with pytest.raises(ValueError) as excinfo:
+ parser = Cmd2ArgParser(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_acarg_narg_single_tuple():
+ with pytest.raises(ValueError) as excinfo:
+ parser = Cmd2ArgParser(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_acarg_narg_tuple_triple():
+ with pytest.raises(ValueError) as excinfo:
+ parser = Cmd2ArgParser(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)
+
+
+def test_acarg_narg_tuple_order():
+ with pytest.raises(ValueError) as excinfo:
+ parser = Cmd2ArgParser(prog='test')
+ parser.add_argument('invalid_tuple', nargs=(2, 1))
+ assert 'Invalid nargs range. The first value must be less than the second' in str(excinfo.value)
+
+
+def test_acarg_narg_tuple_negative():
+ with pytest.raises(ValueError) as excinfo:
+ parser = Cmd2ArgParser(prog='test')
+ parser.add_argument('invalid_tuple', nargs=(-1, 1))
+ assert 'Negative numbers are invalid for nargs range' in str(excinfo.value)
+
+
+def test_acarg_narg_tuple_zero_base():
+ parser = Cmd2ArgParser(prog='test')
+ parser.add_argument('tuple', nargs=(0, 3))
+
+
+def test_acarg_narg_tuple_zero_to_one():
+ parser = Cmd2ArgParser(prog='test')
+ parser.add_argument('tuple', nargs=(0, 1))