def test_read_error_code(self): s = mock.Serial(mock.PPT100(), "COM1") r = pvp.read_error_code(s, 1) self.assertEqual(r, pvp.ErrorCode.NO_ERROR) s = mock.Serial( mock.PPT100(err_state=pvp.ErrorCode.DEFECTIVE_TRANSMITTER), "COM1") r = pvp.read_error_code(s, 1) self.assertEqual(r, pvp.ErrorCode.DEFECTIVE_TRANSMITTER) s = mock.Serial(mock.PPT100(err_state=pvp.ErrorCode.DEFECTIVE_MEMORY), "COM1") r = pvp.read_error_code(s, 1) self.assertEqual(r, pvp.ErrorCode.DEFECTIVE_MEMORY)
def test_io_readline(self): s = mock.Serial(mock.PPT100(), "COM1") sio = io.TextIOWrapper(io.BufferedRWPair(s, s), newline="\r") sio.write("0010073902=?114\r") sio.flush() r = sio.readline() self.assertEqual(r, "0011073906NO_DEF198\r")
def test_flush(self): s = mock.Serial(mock.PPT100(), "COM1") s.flush()
def test_wrong_baudrate(self): s = mock.Serial(mock.PPT100(), "COM1", 19200) s.write(b"0010073902=?114\r") r = s.read(1) self.assertEqual(r, b"")
def test_read(self): s = mock.Serial(mock.PPT100(), "COM1") s.write(b"0010073902=?114\r") r = s.read(1) self.assertEqual(r, b"0")
def test_wrong_type(self): s = mock.Serial(mock.PPT100(), "COM1") with self.assertRaises(TypeError) as context: s.write("blah blah blah")
def test_write(self): s = mock.Serial(mock.PPT100(), "COM1") r = s.write(b"test") self.assertEqual(r, 4)
def test_write_correction_value(self): s = mock.Serial(mock.PPT100(), "COM1") pvp.write_correction_value(s, 1, 1.0)
def test_read_correction_value(self): s = mock.Serial(mock.PPT100(), "COM1") r = pvp.read_correction_value(s, 1) self.assertEqual(r, 1.0)
def test_write_pressure_setpoint(self): s = mock.Serial(mock.PPT100(), "COM1") pvp.write_pressure_setpoint(s, 1, 0) pvp.write_pressure_setpoint(s, 1, 1) with self.assertRaises(ValueError) as context: pvp.write_pressure_setpoint(s, 1, 2)
def test_read_pressure(self): s = mock.Serial(mock.PPT100(), "COM1") r = pvp.read_pressure(s, 1) self.assertEqual(r, 1.0)
def test_read_gauge_type(self): s = mock.Serial(mock.PPT100(), "COM1") r = pvp.read_gauge_type(s, 1) self.assertEqual(r, "PPT 100")
def test_read_software_version(self): s = mock.Serial(mock.PPT100(), "COM1") r = pvp.read_software_version(s, 1) self.assertEqual(r, (1, 1, 0))