@@ -1389,6 +1389,48 @@ def test_echo(capsys):
13891389 assert app ._current_script_dir is None
13901390 assert out .startswith ('{}{}\n ' .format (app .prompt , command ) + 'history [arg]: lists past commands issued' )
13911391
1392+ def test_pseudo_raw_input_tty_rawinput_true (capsys ):
1393+ minput = mock .MagicMock (name = 'input' , side_effect = ['set' , 'quit' ])
1394+ sm .input = minput
1395+ mtty = mock .MagicMock (name = 'isatty' , return_value = True )
1396+ sys .stdin .isatty = mtty
1397+
1398+ # run the cmdloop, which should pull input from the mocked input
1399+ app = cmd2 .Cmd ()
1400+ app .use_rawinput = True
1401+ app .abbrev = False
1402+ app ._cmdloop ()
1403+ out , err = capsys .readouterr ()
1404+
1405+ # because we mocked the input() call, we won't see the prompt
1406+ # or the name of the command in the output, so we can't check
1407+ # if its there. We assume that if input got called twice, once
1408+ # for the 'set' command, and once for the 'quit' command,
1409+ # that the rest of it worked
1410+ assert minput .call_count == 2
1411+
1412+ def test_pseudo_raw_input_tty_rawinput_false (capsys ):
1413+ # mock up the input
1414+ fakein = io .StringIO (u'{}' .format ('set\n quit\n ' ))
1415+ mtty = mock .MagicMock (name = 'isatty' , return_value = True )
1416+ fakein .isatty = mtty
1417+ mreadline = mock .MagicMock (name = 'readline' , wraps = fakein .readline )
1418+ fakein .readline = mreadline
1419+
1420+ # run the cmdloop, telling it where to get input from
1421+ app = cmd2 .Cmd (stdin = fakein )
1422+ app .use_rawinput = False
1423+ app .abbrev = False
1424+ app ._cmdloop ()
1425+ out , err = capsys .readouterr ()
1426+
1427+ # because we mocked the readline() call, we won't see the prompt
1428+ # or the name of the command in the output, so we can't check
1429+ # if its there. We assume that if readline() got called twice, once
1430+ # for the 'set' command, and once for the 'quit' command,
1431+ # that the rest of it worked
1432+ assert mreadline .call_count == 2
1433+
13921434# the next helper function and two tests check for piped
13931435# input when use_rawinput is True.
13941436#
0 commit comments