Exemplo n.º 1
0
def test_loopbackcomm_read_raw():
    mock_stdin = mock.MagicMock()
    mock_stdin.read.side_effect = [b"a", b"b", b"c", b"\n"]
    comm = LoopbackCommunicator(stdin=mock_stdin)

    assert comm.read_raw() == b"abc"
    mock_stdin.read.assert_has_calls([mock.call(1)]*4)
    assert mock_stdin.read.call_count == 4

    mock_stdin.read = mock.MagicMock()
    comm.read_raw(10)
    mock_stdin.read.assert_called_with(10)
Exemplo n.º 2
0
def test_loopbackcomm_read_raw():
    mock_stdin = mock.MagicMock()
    mock_stdin.read.side_effect = [b"a", b"b", b"c", b"\n"]
    comm = LoopbackCommunicator(stdin=mock_stdin)

    assert comm.read_raw() == b"abc"
    mock_stdin.read.assert_has_calls([mock.call(1)]*4)
    assert mock_stdin.read.call_count == 4

    mock_stdin.read = mock.MagicMock()
    comm.read_raw(10)
    mock_stdin.read.assert_called_with(10)
Exemplo n.º 3
0
def test_loopbackcomm_read_raw_2char_terminator():
    mock_stdin = mock.MagicMock()
    mock_stdin.read.side_effect = [b"a", b"b", b"c", b"\r", b"\n"]
    comm = LoopbackCommunicator(stdin=mock_stdin)
    comm._terminator = "\r\n"

    assert comm.read_raw() == b"abc"
    mock_stdin.read.assert_has_calls([mock.call(1)]*5)
    assert mock_stdin.read.call_count == 5
Exemplo n.º 4
0
def test_loopbackcomm_read_raw_2char_terminator():
    mock_stdin = mock.MagicMock()
    mock_stdin.read.side_effect = [b"a", b"b", b"c", b"\r", b"\n"]
    comm = LoopbackCommunicator(stdin=mock_stdin)
    comm._terminator = "\r\n"

    assert comm.read_raw() == b"abc"
    mock_stdin.read.assert_has_calls([mock.call(1)]*5)
    assert mock_stdin.read.call_count == 5
Exemplo n.º 5
0
def test_loopbackcomm_read_raw_terminator_is_empty_string():
    mock_stdin = mock.MagicMock()
    mock_stdin.read.side_effect = [b"abc"]
    comm = LoopbackCommunicator(stdin=mock_stdin)
    comm._terminator = ""

    assert comm.read_raw() == b"abc"
    mock_stdin.read.assert_has_calls([mock.call(-1)])
    assert mock_stdin.read.call_count == 1
Exemplo n.º 6
0
def test_loopbackcomm_read_raw_size_invalid():
    with pytest.raises(ValueError):
        mock_stdin = mock.MagicMock()
        mock_stdin.read.side_effect = [b"abc"]
        comm = LoopbackCommunicator(stdin=mock_stdin)
        comm.read_raw(size=-2)