@@ -1344,11 +1344,11 @@ def test_select_options(select_app):
13441344 # And verify the expected output to stdout
13451345 assert out == expected
13461346
1347- def test_select_invalid_option (select_app ):
1347+ def test_select_invalid_option_too_big (select_app ):
13481348 # Mock out the input call so we don't actually wait for a user's response on stdin
13491349 m = mock .MagicMock (name = 'input' )
13501350 # 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
13521352 builtins .input = m
13531353
13541354 food = 'fish'
@@ -1368,6 +1368,30 @@ def test_select_invalid_option(select_app):
13681368 # And verify the expected output to stdout
13691369 assert out == expected
13701370
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+
13711395def test_select_list_of_strings (select_app ):
13721396 # Mock out the input call so we don't actually wait for a user's response on stdin
13731397 m = mock .MagicMock (name = 'input' , return_value = '2' )
0 commit comments