summaryrefslogtreecommitdiff
path: root/tests/test_cmd2.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-01-08 21:30:48 -0500
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-01-08 21:30:48 -0500
commit0ee0769838961aedc73a616692ec268ab7d0266f (patch)
tree83800155fcd7a8347053566d44ebca7241a323eb /tests/test_cmd2.py
parentd9dc236a70e9e450951cf8c75318e1eaa9946a60 (diff)
parentfe324f2fa74d556a0c154632c88c9049da8d75bc (diff)
downloadcmd2-git-0ee0769838961aedc73a616692ec268ab7d0266f.tar.gz
Merge branch 'master' into history
Diffstat (limited to 'tests/test_cmd2.py')
-rw-r--r--tests/test_cmd2.py28
1 files changed, 26 insertions, 2 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 008f2cc6..350991fa 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -1333,11 +1333,11 @@ def test_select_options(select_app):
# And verify the expected output to stdout
assert out == expected
-def test_select_invalid_option(select_app):
+def test_select_invalid_option_too_big(select_app):
# Mock out the input call so we don't actually wait for a user's response on stdin
m = mock.MagicMock(name='input')
# If side_effect is an iterable then each call to the mock will return the next value from the iterable.
- m.side_effect = ['3', '1'] # First pass and invalid selection, then pass a valid one
+ m.side_effect = ['3', '1'] # First pass an invalid selection, then pass a valid one
builtins.input = m
food = 'fish'
@@ -1357,6 +1357,30 @@ def test_select_invalid_option(select_app):
# And verify the expected output to stdout
assert out == expected
+def test_select_invalid_option_too_small(select_app):
+ # Mock out the input call so we don't actually wait for a user's response on stdin
+ m = mock.MagicMock(name='input')
+ # If side_effect is an iterable then each call to the mock will return the next value from the iterable.
+ m.side_effect = ['0', '1'] # First pass an invalid selection, then pass a valid one
+ builtins.input = m
+
+ food = 'fish'
+ out = run_cmd(select_app, "eat {}".format(food))
+ expected = normalize("""
+ 1. sweet
+ 2. salty
+'0' isn't a valid choice. Pick a number between 1 and 2:
+{} with sweet sauce, yum!
+""".format(food))
+
+ # Make sure our mock was called exactly twice with the expected arguments
+ arg = 'Sauce? '
+ calls = [mock.call(arg), mock.call(arg)]
+ m.assert_has_calls(calls)
+
+ # And verify the expected output to stdout
+ assert out == expected
+
def test_select_list_of_strings(select_app):
# Mock out the input call so we don't actually wait for a user's response on stdin
m = mock.MagicMock(name='input', return_value='2')