Exemplo n.º 1
0
def test_sets_terminal_special_chars(mock_serial, mock_console):
    term = terminal.SerialTerminal(mock_serial())

    assert term.exit_character == terminal.CTRL_C
    assert term.menu_character == terminal.CTRL_T
    assert term.reset_character == terminal.CTRL_B
    assert term.help_character == terminal.CTRL_H
Exemplo n.º 2
0
def test_stops_terminal_on_keyboard_interrupt(mock_serial, mock_console):
    term = terminal.SerialTerminal(mock_serial())
    term.alive = True
    mock_console().getkey.side_effect = KeyboardInterrupt()

    term.writer()

    assert term.alive is False
Exemplo n.º 3
0
def test_stops_terminal_when_ctrl_c_received(mock_serial, mock_console):
    term = terminal.SerialTerminal(mock_serial())
    term.alive = True
    mock_console().getkey.return_value = terminal.CTRL_C

    term.writer()

    assert term.alive is False
Exemplo n.º 4
0
def test_ctrl_b_sends_reset_to_serial_port(mock_serial, mock_console):
    term = terminal.SerialTerminal(mock_serial())
    term.alive = True
    mock_console().getkey.side_effect = (terminal.CTRL_B, )

    with pytest.raises(StopIteration):
        term.writer()

    mock_serial().sendBreak.assert_called_once()
Exemplo n.º 5
0
def test_echo_to_console_can_be_enabled(mock_serial, mock_console):
    term = terminal.SerialTerminal(mock_serial(), echo=True)
    term.alive = True
    normal_char = "h"
    mock_console().getkey.side_effect = (normal_char, )

    with pytest.raises(StopIteration):
        term.writer()

    mock_console().write.assert_called_once_with(normal_char)
Exemplo n.º 6
0
def test_echo_to_console_is_default_disabled(mock_serial, mock_console):
    term = terminal.SerialTerminal(mock_serial())
    term.alive = True
    normal_char = "h"
    mock_console().getkey.side_effect = (normal_char, )

    with pytest.raises(StopIteration):
        term.writer()

    mock_console().write.assert_not_called()
Exemplo n.º 7
0
def test_ctrl_h_prints_help_text(mock_serial, mock_console):
    sys.stderr.write = mock.Mock()
    term = terminal.SerialTerminal(mock_serial())
    term.alive = True
    mock_console().getkey.side_effect = (terminal.CTRL_H, )

    with pytest.raises(StopIteration):
        term.writer()

    sys.stderr.write.assert_called_once_with(term.get_help_text())
Exemplo n.º 8
0
def test_ignores_invalid_menu_key(menu_key, mock_serial, mock_console):
    term = terminal.SerialTerminal(mock_serial())
    term.handle_menu_key = mock.Mock()
    term.alive = True
    mock_console().getkey.side_effect = (terminal.CTRL_T, menu_key)

    with pytest.raises(StopIteration):
        term.writer()

    term.handle_menu_key.assert_not_called()
Exemplo n.º 9
0
def test_handles_valid_menu_key(menu_key, mock_serial, mock_console):
    term = terminal.SerialTerminal(mock_serial())
    term.handle_menu_key = mock.Mock()
    term.alive = True
    mock_console().getkey.side_effect = (terminal.CTRL_T, menu_key,
                                         terminal.CTRL_C)

    term.writer()

    term.handle_menu_key.assert_called_once_with(menu_key)
Exemplo n.º 10
0
def test_writes_normal_char_to_serial_output(mock_serial, mock_console):
    term = terminal.SerialTerminal(mock_serial())
    term.alive = True
    normal_char = "h"
    mock_console().getkey.side_effect = (normal_char, )

    with pytest.raises(StopIteration):
        term.writer()

    mock_serial().write.assert_called_once_with(
        term.tx_encoder.encode(normal_char))
Exemplo n.º 11
0
def test_sets_terminal_rx_and_tx_encoding_to_utf8(mock_serial, mock_console):
    term = terminal.SerialTerminal(mock_serial())

    assert term.input_encoding == "UTF-8"
    assert term.output_encoding == "UTF-8"
Exemplo n.º 12
0
def test_help_text_is_correct(mock_serial, mock_console):
    term = terminal.SerialTerminal(mock_serial())

    assert term.get_help_text() == terminal.HELP_TEXT
Exemplo n.º 13
0
def test_reset_sends_serial_break(mock_serial, mock_console):
    term = terminal.SerialTerminal(mock_serial())

    term.reset()

    mock_serial().sendBreak.assert_called_once()