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()
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)
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")
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)
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)
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)
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' }
def test_instanziation_fail_missing_port(self, target): with pytest.raises(NoSupplierFoundError): SerialDriver(target, "serial")
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)
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()
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)
def serial_driver_no_name(target, serial_port, mocker): m = mocker.patch('serial.Serial') s = SerialDriver(target, None) target.activate(s) return s
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)
def serial_driver(target, serial_port, monkeypatch): serial_mock = MagicMock import serial monkeypatch.setattr(serial, 'Serial', serial_mock) s = SerialDriver(target) return s
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)
def test_instanziation_fail_missing_port(self, target): with pytest.raises(NoResourceFoundError): SerialDriver(target)