@@ -1344,11 +1344,11 @@ def test_select_options(select_app):
1344
1344
# And verify the expected output to stdout
1345
1345
assert out == expected
1346
1346
1347
- def test_select_invalid_option (select_app ):
1347
+ def test_select_invalid_option_too_big (select_app ):
1348
1348
# Mock out the input call so we don't actually wait for a user's response on stdin
1349
1349
m = mock .MagicMock (name = 'input' )
1350
1350
# If side_effect is an iterable then each call to the mock will return the next value from the iterable.
1351
- m .side_effect = ['3' , '1' ] # First pass and invalid selection, then pass a valid one
1351
+ m .side_effect = ['3' , '1' ] # First pass an invalid selection, then pass a valid one
1352
1352
builtins .input = m
1353
1353
1354
1354
food = 'fish'
@@ -1368,6 +1368,30 @@ def test_select_invalid_option(select_app):
1368
1368
# And verify the expected output to stdout
1369
1369
assert out == expected
1370
1370
1371
+ def test_select_invalid_option_too_small (select_app ):
1372
+ # Mock out the input call so we don't actually wait for a user's response on stdin
1373
+ m = mock .MagicMock (name = 'input' )
1374
+ # If side_effect is an iterable then each call to the mock will return the next value from the iterable.
1375
+ m .side_effect = ['0' , '1' ] # First pass an invalid selection, then pass a valid one
1376
+ builtins .input = m
1377
+
1378
+ food = 'fish'
1379
+ out = run_cmd (select_app , "eat {}" .format (food ))
1380
+ expected = normalize ("""
1381
+ 1. sweet
1382
+ 2. salty
1383
+ '0' isn't a valid choice. Pick a number between 1 and 2:
1384
+ {} with sweet sauce, yum!
1385
+ """ .format (food ))
1386
+
1387
+ # Make sure our mock was called exactly twice with the expected arguments
1388
+ arg = 'Sauce? '
1389
+ calls = [mock .call (arg ), mock .call (arg )]
1390
+ m .assert_has_calls (calls )
1391
+
1392
+ # And verify the expected output to stdout
1393
+ assert out == expected
1394
+
1371
1395
def test_select_list_of_strings (select_app ):
1372
1396
# Mock out the input call so we don't actually wait for a user's response on stdin
1373
1397
m = mock .MagicMock (name = 'input' , return_value = '2' )
0 commit comments