summaryrefslogtreecommitdiff
path: root/tests/test_acargparse.py
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2018-04-19 21:51:24 -0600
committerkotfu <kotfu@kotfu.net>2018-04-19 21:51:24 -0600
commit477666d0b3e097fb831729644b8861a983805981 (patch)
tree02217d3d2bb03499e511d8dd1774d161bb019a0f /tests/test_acargparse.py
parentb7cfb130c7c914478936366b748b04234b031119 (diff)
parent58fdd089cc064e71502dc1f094fd906d30523886 (diff)
downloadcmd2-git-477666d0b3e097fb831729644b8861a983805981.tar.gz
Merge branch 'master' into ply
Diffstat (limited to 'tests/test_acargparse.py')
-rw-r--r--tests/test_acargparse.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/test_acargparse.py b/tests/test_acargparse.py
new file mode 100644
index 00000000..be3e8b97
--- /dev/null
+++ b/tests/test_acargparse.py
@@ -0,0 +1,53 @@
+"""
+Unit/functional testing for argparse customizations in cmd2
+
+Copyright 2018 Eric Lin <anselor@gmail.com>
+Released under MIT license, see LICENSE file
+"""
+import pytest
+from cmd2.argparse_completer import ACArgumentParser
+
+
+def test_acarg_narg_empty_tuple():
+ with pytest.raises(ValueError) as excinfo:
+ parser = ACArgumentParser(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 = ACArgumentParser(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 = ACArgumentParser(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 = ACArgumentParser(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 = ACArgumentParser(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 = ACArgumentParser(prog='test')
+ parser.add_argument('tuple', nargs=(0, 3))
+
+
+def test_acarg_narg_tuple_zero_to_one():
+ parser = ACArgumentParser(prog='test')
+ parser.add_argument('tuple', nargs=(0, 1))