def test_properties(self, mock_logger): ds = DutSerial() self.assertFalse(ds.ch_mode) ds.ch_mode = True self.assertTrue(ds.ch_mode) self.assertEqual(ds.ch_mode_chunk_size, 1) ds.ch_mode_chunk_size = 2 self.assertEqual(ds.ch_mode_chunk_size, 2) self.assertEqual(ds.ch_mode_ch_delay, 0.01) ds.ch_mode_ch_delay = 0.02 self.assertEqual(ds.ch_mode_ch_delay, 0.02) self.assertEqual(ds.ch_mode_start_delay, 0) ds.ch_mode_start_delay = 1 self.assertEqual(ds.ch_mode_start_delay, 1) self.assertEqual(ds.serial_baudrate, 460800) ds.serial_baudrate = 9600 self.assertEqual(ds.serial_baudrate, 9600) self.assertEqual(ds.serial_timeout, 0.01) ds.serial_timeout = 0.02 self.assertEqual(ds.serial_timeout, 0.02) self.assertFalse(ds.serial_xonxoff) ds.serial_xonxoff = True self.assertTrue(ds.serial_xonxoff) self.assertFalse(ds.serial_rtscts) ds.serial_rtscts = True self.assertTrue(ds.serial_rtscts)
def test_writeline(self, mock_logger): ds = DutSerial() mock_port = mock.MagicMock() mock_port.write = mock.MagicMock( side_effect=[1, 1, 1, 1, SerialException]) ds.port = mock_port ds.ch_mode = False ds.writeline("data") mock_port.write.assert_called_once_with("data\n".encode()) mock_port.reset_mock() ds.ch_mode = True ds.ch_mode_chunk_size = 2 ds.writeline("data") mock_port.write.assert_has_calls([ mock.call("da".encode()), mock.call("ta".encode()), mock.call("\n".encode()) ]) with self.assertRaises(RuntimeError): ds.writeline("data")