def test_pseudo_raw_input_tty_rawinput_false():
# gin up some input like it's coming from a tty
fakein = io.StringIO(u'{}'.format('set\n'))
mtty = mock.MagicMock(name='isatty', return_value=True)
fakein.isatty = mtty
mreadline = mock.MagicMock(name='readline', wraps=fakein.readline)
fakein.readline = mreadline
# run the cmdloop, telling it where to get input from
app = cmd2.Cmd(stdin=fakein)
app.use_rawinput = False
app._cmdloop()
# because we mocked the readline() call, we won't get the prompt
# or the name of the command in the output, so we can't check
# if its there. We assume that if readline() got called twice, once
# for the 'set' command, and once for the 'quit' command,
# that the rest of it worked
assert mreadline.call_count == 2
# the next helper function and two tests check for piped
# input when use_rawinput is True.
评论列表
文章目录