Exemplo n.º 1
0
def test_filecomm_terminator():
    comm = FileCommunicator(mock.MagicMock())

    assert comm.terminator == "\n"

    comm.terminator = "*"
    assert comm._terminator == "*"

    comm.terminator = b"*"
    assert comm._terminator == "*"
Exemplo n.º 2
0
def test_filecomm_terminator():
    comm = FileCommunicator(mock.MagicMock())

    eq_(comm.terminator, "\n")

    comm.terminator = "*"
    eq_(comm._terminator, "*")

    comm.terminator = b"*"  # pylint: disable=redefined-variable-type
    eq_(comm._terminator, "*")
Exemplo n.º 3
0
def test_filecomm_terminator():
    comm = FileCommunicator(mock.MagicMock())

    eq_(comm.terminator, "\n")

    comm.terminator = "*"
    eq_(comm._terminator, "*")

    comm.terminator = b"*"
    eq_(comm._terminator, "*")
Exemplo n.º 4
0
def test_filecomm_read_raw():
    comm = FileCommunicator(mock.MagicMock())
    comm._filelike.read = mock.MagicMock(side_effect=[b"a", b"b", b"c", b"\n"])

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

    comm._filelike.read = mock.MagicMock()
    comm.read_raw(10)
    comm._filelike.read.assert_called_with(10)
Exemplo n.º 5
0
def test_filecomm_read_raw():
    comm = FileCommunicator(mock.MagicMock())
    comm._filelike.read = mock.MagicMock(side_effect=[b"a", b"b", b"c", b"\n"])

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

    comm._filelike.read = mock.MagicMock()
    comm.read_raw(10)
    comm._filelike.read.assert_called_with(10)
Exemplo n.º 6
0
def test_filecomm_address_getter_no_name():
    mock_file = mock.MagicMock()
    comm = FileCommunicator(mock_file)

    del comm._filelike.name

    assert comm.address is None
Exemplo n.º 7
0
def test_filecomm_address_getter():
    mock_file = mock.MagicMock()
    comm = FileCommunicator(mock_file)

    mock_name = mock.PropertyMock(return_value="/home/user/file")
    type(comm._filelike).name = mock_name

    assert comm.address == "/home/user/file"
    mock_name.assert_called_with()
Exemplo n.º 8
0
 def open_file(cls, filename):
     """
     Given a file, treats that file as a character device file that can
     be read from and written to in order to communicate with the
     instrument. This may be the case, for instance, if the instrument
     is connected by the Linux ``usbtmc`` kernel driver.
     
     :param str filename: Name of the character device to open.
     
     :rtype: `Instrument`
     :return: Object representing the connected instrument.
     """
     return cls(FileCommunicator(filename))
Exemplo n.º 9
0
def test_filecomm_seek():
    comm = FileCommunicator(mock.MagicMock())
    comm.seek(1)
    comm._filelike.seek.assert_called_with(1)
Exemplo n.º 10
0
def test_filecomm_timeout_setter():
    with pytest.raises(NotImplementedError):
        comm = FileCommunicator(mock.MagicMock())
        comm.timeout = 1
Exemplo n.º 11
0
def test_filecomm_tell():
    comm = FileCommunicator(mock.MagicMock())
    comm._filelike.tell.return_value = 5

    eq_(comm.tell(), 5)
    comm._filelike.tell.assert_called_with()
Exemplo n.º 12
0
def test_filecomm_address_setter():
    with pytest.raises(NotImplementedError):
        comm = FileCommunicator(mock.MagicMock())
        comm.address = "abc123"
Exemplo n.º 13
0
def test_filecomm_close():
    comm = FileCommunicator(mock.MagicMock())

    comm.close()
    comm._filelike.close.assert_called_with()
Exemplo n.º 14
0
def test_filecomm_flush_input():
    comm = FileCommunicator(mock.MagicMock())
    comm.flush_input()
    comm._filelike.flush.assert_called_with()
Exemplo n.º 15
0
def test_filecomm_tell():
    comm = FileCommunicator(mock.MagicMock())
    comm._filelike.tell.return_value = 5

    assert comm.tell() == 5
    comm._filelike.tell.assert_called_with()
Exemplo n.º 16
0
def test_filecomm_write_raw():
    comm = FileCommunicator(mock.MagicMock())

    comm.write_raw(b"mock")
    comm._filelike.write.assert_called_with(b"mock")
Exemplo n.º 17
0
def test_filecomm_sendcmd():
    comm = FileCommunicator(mock.MagicMock())

    comm._sendcmd("mock")
    comm._filelike.write.assert_called_with(b"mock\n")
Exemplo n.º 18
0
def test_filecomm_seek():
    comm = FileCommunicator(mock.MagicMock())
    comm.seek(1)
    comm._filelike.seek.assert_called_with(1)
Exemplo n.º 19
0
def test_filecomm_sendcmd():
    comm = FileCommunicator(mock.MagicMock())

    comm._sendcmd("mock")
    comm._filelike.write.assert_called_with(b"mock\n")
Exemplo n.º 20
0
def test_filecomm_write_raw():
    comm = FileCommunicator(mock.MagicMock())

    comm.write_raw(b"mock")
    comm._filelike.write.assert_called_with(b"mock")
Exemplo n.º 21
0
def test_filecomm_address_setter():
    comm = FileCommunicator(mock.MagicMock())
    comm.address = "abc123"
Exemplo n.º 22
0
def test_filecomm_close():
    comm = FileCommunicator(mock.MagicMock())

    comm.close()
    comm._filelike.close.assert_called_with()
Exemplo n.º 23
0
def test_filecomm_flush_input():
    comm = FileCommunicator(mock.MagicMock())
    comm.flush_input()
    comm._filelike.flush.assert_called_with()
Exemplo n.º 24
0
def test_filecomm_query():
    comm = FileCommunicator(mock.MagicMock())
    comm._testing = True  # to disable the delay in the _query function
    comm._filelike.read = mock.MagicMock(side_effect=[b"a", b"b", b"c", b"\n"])

    eq_(comm._query("mock"), "abc")
Exemplo n.º 25
0
def test_filecomm_init():
    mock_file = mock.MagicMock()
    comm = FileCommunicator(mock_file)
    assert comm._filelike is mock_file
Exemplo n.º 26
0
def test_filecomm_query():
    comm = FileCommunicator(mock.MagicMock())
    comm._testing = True  # to disable the delay in the _query function
    comm._filelike.read = mock.MagicMock(side_effect=[b"a", b"b", b"c", b"\n"])

    assert comm._query("mock") == "abc"
Exemplo n.º 27
0
def test_filecomm_timeout_setter():
    comm = FileCommunicator(mock.MagicMock())
    comm.timeout = 1