def test_restore_terminal(self, _stdin, _tcsetattr, _fcntl): fd = 42 _stdin.fileno.return_value = fd cli = epdb_client.TelnetClient() with mock.patch.object(cli, "sock") as sock: cli.restore_terminal() sock.sendall.assert_not_called() _tcsetattr.assert_not_called() _fcntl.assert_not_called()
def test_updateTerminalSize(self, _stdin, _ioctl): fd = 42 _stdin.fileno.return_value = fd _ioctl.return_value = b'\x19\0\x50\0\0\0\0\0' exp = b'\xff\xfa\x1f\x00\x50\x00\x19\xff\xf0' cli = epdb_client.TelnetClient() with mock.patch.object(cli, "sock") as sock: cli.updateTerminalSize() sock.sendall.assert_called_once_with(exp)
def test_ctrl_c(self): intr = mock.MagicMock() tb = mock.MagicMock() cli = epdb_client.TelnetClient() with mock.patch.object(cli, "sock") as sock: self.assertRaises(KeyboardInterrupt, cli.ctrl_c, intr, tb) self.assertEqual([ mock.call(epdb_client.IAC + epdb_client.IP), mock.call(b'close\n'), ], sock.sendall.call_args_list)
def test_restore_terminal__oldTerm(self, _stdin, _tcsetattr, _fcntl): fd = 42 _stdin.fileno.return_value = fd old_term = mock.MagicMock() old_flags = mock.MagicMock() cli = epdb_client.TelnetClient() cli.oldTerm = old_term cli.oldFlags = old_flags with mock.patch.object(cli, "sock") as sock: cli.restore_terminal() sock.sendall.assert_not_called() _tcsetattr.assert_called_once_with(fd, epdb_client.termios.TCSAFLUSH, old_term) _fcntl.assert_called_once_with(fd, epdb_client.fcntl.F_SETFL, old_flags)
def test_interact__read(self, _stdin, _stdout, _set_raw_mode, _updateTerminalSize, _read_eager, _select): fd = 42 _stdin.fileno.return_value = fd cli = epdb_client.TelnetClient() def _fake_read_eager(): cli.eof = True return b"abc" _select.return_value = [[cli], [_stdout], []] _read_eager.side_effect = _fake_read_eager with mock.patch.object(cli, "sock") as sock: cli.interact() _read_eager.assert_called_once_with() _stdout.write.assert_called_once_with('abc') _stdout.flush.assert_called_once_with() sock.sendall.assert_not_called()
def test_set_raw_mode(self, _stdin, _tcgetattr, _tcsetattr, _fcntl): fd = 42 _stdin.fileno.return_value = 42 newattr = [object(), object(), object(), 255] _tcgetattr.return_value = newattr fcntlret = _fcntl.return_value cli = epdb_client.TelnetClient() with mock.patch.object(cli, "sock") as sock: cli.set_raw_mode() sock.sendall.assert_not_called() _tcgetattr.assert_called_with(fd) exp_attr = newattr[:3] + [245] _tcsetattr.assert_called_once_with(fd, epdb_client.termios.TCSANOW, exp_attr) self.assertEqual([ mock.call(fd, epdb_client.fcntl.F_GETFL), mock.call(fd, epdb_client.fcntl.F_SETFL, fcntlret.__or__.return_value), ], _fcntl.call_args_list) self.assertEqual(_fcntl.return_value, cli.oldFlags) fcntlret.__or__.assert_called_once_with(epdb_client.os.O_NONBLOCK) self.assertEqual(newattr, cli.oldTerm) self.assertEqual(_fcntl.return_value, cli.oldFlags)
def test_write_with_termkey(self): data = b"aaa" + epdb_client.TERMKEY + b"bbb" cli = epdb_client.TelnetClient() with mock.patch.object(cli, "sock") as sock: cli.write(data) sock.sendall.assert_called_once_with(data[:3])
def test_write(self): data = b"aaa" cli = epdb_client.TelnetClient() with mock.patch.object(cli, "sock") as sock: cli.write(data) sock.sendall.assert_called_once_with(data)