def test_run_invokes_the_proper_methods(self): with h.mock_value(term.tty_engine, "_loop") as mymock: session = mock.Mock() term.tty_engine().run(lambda _: session) self.assertEqual(1, session.on_begin.call_count) self.assertEqual(1, mymock[0].call_count) self.assertEqual(1, session.on_end.call_count)
def test__loop_turns_raw_mode_on(self): values = ["f"] def read_f(l): self.assertEqual(1, l) if (len(values) == 0): raise(EOFError()) return(values.pop()) with h.mock_value( sys, "stdin", termios, "tcgetattr", tty, "setraw", termios, "tcsetattr" ) as mymock: mymock[0].read.side_effect = read_f session = mock.Mock() term.tty_engine().run(lambda _: session) self.assertEqual(1, mymock[1].call_count) self.assertEqual(1, mymock[2].call_count) self.assertEqual(1, mymock[3].call_count) session.on_data.assert_called_with("f")
def test_run_uses_sys_transport(self): with h.mock_value(term.tty_engine, "_loop") as mymock: factory = mock.Mock() term.tty_engine().run(factory) self.assertTrue(isinstance(factory.call_args[0][0], system.sys_transport))
def test_simpleterm_bindings_defines_BACKSPACE(self): with h.mock_value(keystroke.keystroke, "unhandle") as mymock: k = keystroke.keystroke() k.simpleterm_bindings(mock.Mock()) k.do_handle("") self.assertEqual(1, mymock[0].call_count)
def test_stamp_uses_current_timestap(self): with h.mock_value(keystroke, "now") as mymock: mymock[0].return_value = "now" k = keystroke.keystroke() self.assertEqual(("x","now"), k._stamp("x"))
def test_write_uses_sys_stdout(self): with h.mock_value(sys, "stdout") as mymock: t = system.sys_transport() t.write("foobar") mymock[0].write.assert_called_with("foobar")
def test_cancel_invokes_do_cancel(self): with h.mock_value(handler.handler, "do_cancel") as mymock: hl = handler.handler() hl.do_cancel() mymock[0].assert_called_with()