Esempio n. 1
0
 def test_close(self, target, serial_port, mocker):
     serial_mock = mocker.patch('serial.Serial')
     s = SerialDriver(target, "serial")
     target.activate(s)
     s.close()
     serial_mock.return_value.open.assert_called_once_with()
     serial_mock.return_value.close.assert_called_once_with()
Esempio n. 2
0
 def test_read(self, target, serial_port, mocker):
     serial_mock = mocker.patch('serial.Serial')
     serial_mock.return_value.in_waiting = 0
     s = SerialDriver(target, "serial")
     target.activate(s)
     s.read()
     serial_mock.return_value.open.assert_called_once_with()
     serial_mock.return_value.read.assert_called_once_with(1)
Esempio n. 3
0
 def test_write(self, target, monkeypatch, serial_port, mocker):
     serial_mock = mocker.Mock()
     serial_mock.write = mocker.MagicMock()
     monkeypatch.setattr(serial, 'Serial', serial_mock)
     s = SerialDriver(target)
     s.serial = serial_mock
     target.activate(s)
     s.write(b"testdata")
     serial_mock.write.assert_called_with(b"testdata")
Esempio n. 4
0
 def test_close(self, target, monkeypatch, serial_port, mocker):
     serial_mock = mocker.Mock()
     serial_mock.close = mocker.MagicMock()
     monkeypatch.setattr(serial, 'Serial', serial_mock)
     s = SerialDriver(target)
     s.serial = serial_mock
     target.activate(s)
     s.close()
     assert (serial_mock.close.called)
Esempio n. 5
0
 def test_read(self, target, monkeypatch, serial_port, mocker):
     serial_mock = mocker.Mock()
     serial_mock.read = mocker.MagicMock()
     serial_mock.in_waiting = 0
     monkeypatch.setattr(serial, 'Serial', serial_mock)
     s = SerialDriver(target)
     s.serial = serial_mock
     target.activate(s)
     s.read()
     assert (serial_mock.read.called)
Esempio n. 6
0
 def test_read(self, target, monkeypatch, serial_port):
     serial_mock = Mock()
     serial_mock.read = MagicMock()
     monkeypatch.setattr(serial, 'Serial', serial_mock)
     s = SerialDriver(target)
     s.serial = serial_mock
     s.on_activate()
     s.read()
     assert (serial_mock.read.called)
Esempio n. 7
0
def test_export_network_serial(target):
    NetworkSerialPort(target, None, host='testhost', port=12345, speed=115200)
    SerialDriver(target, None)

    exported = target.export()
    assert exported == {
        'LG__SERIALDRIVER_HOST': 'testhost',
        'LG__SERIALDRIVER_PORT': '12345',
        'LG__SERIALDRIVER_PROTOCOL': 'rfc2217',
        'LG__SERIALDRIVER_SPEED': '115200'
    }
Esempio n. 8
0
 def test_instanziation_fail_missing_port(self, target):
     with pytest.raises(NoSupplierFoundError):
         SerialDriver(target, "serial")
Esempio n. 9
0
 def test_raw_instanziation(self, target, serial_raw_port, mocker):
     serial_mock = mocker.patch('serial.serial_for_url')
     s = SerialDriver(target, "serial")
     assert (isinstance(s, SerialDriver))
     assert (target.drivers[0] == s)
     serial_mock.assert_called_once_with('socket://', do_not_open=True)
Esempio n. 10
0
 def test_rfc2711_instanziation(self, target, serial_rfc2711_port, mocker):
     serial_mock = mocker.patch('serial.rfc2217.Serial')
     s = SerialDriver(target, "serial")
     assert (isinstance(s, SerialDriver))
     assert (target.drivers[0] == s)
     serial_mock.assert_called_once_with()
Esempio n. 11
0
 def test_instanziation(self, target, serial_port, mocker):
     serial_mock = mocker.patch('serial.Serial')
     s = SerialDriver(target, "serial")
     assert (isinstance(s, SerialDriver))
     assert (target.drivers[0] == s)
Esempio n. 12
0
def serial_driver_no_name(target, serial_port, mocker):
    m = mocker.patch('serial.Serial')
    s = SerialDriver(target, None)
    target.activate(s)
    return s
Esempio n. 13
0
 def test_instanziation(self, target, serial_port, monkeypatch):
     serial_mock = Mock()
     monkeypatch.setattr(serial, 'Serial', serial_mock)
     s = SerialDriver(target)
     assert (isinstance(s, SerialDriver))
     assert (target.drivers[0] == s)
Esempio n. 14
0
def serial_driver(target, serial_port, monkeypatch):
    serial_mock = MagicMock
    import serial
    monkeypatch.setattr(serial, 'Serial', serial_mock)
    s = SerialDriver(target)
    return s
Esempio n. 15
0
 def test_rfc2711_instanziation(self, target, serial_rfc2711_port, monkeypatch, mocker):
     serial_mock = mocker.Mock()
     monkeypatch.setattr(serial, 'Serial', serial_mock)
     s = SerialDriver(target, "serial")
     assert (isinstance(s, SerialDriver))
     assert (target.drivers[0] == s)
Esempio n. 16
0
 def test_instanziation_fail_missing_port(self, target):
     with pytest.raises(NoResourceFoundError):
         SerialDriver(target)