def test_set_pi_parameters_timeout(): serial = MockSerial(INVALID_RESPONSE) attiny = AttinyProtocol(serial) with pytest.raises(InvalidResponseException): attiny.set_pi_parameters(0, 0, 0) assert len(serial.received) == 6 assert serial.received[:1] == SET_PI
def test_set_pi_parameters_timeout(): serial = MockSerial(b'') attiny = AttinyProtocol(serial) result = attiny.set_pi_parameters(0, 0, 0) assert len(serial.received) == 6 assert result == False
def test_set_pi_parameters_max(): serial = MockSerial(ACK) attiny = AttinyProtocol(serial) result = attiny.set_pi_parameters(INT16_MAX, INT16_MAX, UINT8_MAX) assert result == True assert len(serial.received) == 6 assert serial.received[:1] == SET_PI assert serial.received[1:3] == INT16_MAX_ENCODED assert serial.received[3:5] == INT16_MAX_ENCODED assert serial.received[5:] == UINT8_MAX_ENCODED
def test_set_pi_parameters_inrange(): p = 0 i = -1 s = 1 p_encoded = p.to_bytes(2, 'big', signed=True) i_encoded = i.to_bytes(2, 'big', signed=True) s_encoded = s.to_bytes(1, 'big') serial = MockSerial(ACK) attiny = AttinyProtocol(serial) result = attiny.set_pi_parameters(p, i, s) assert result == True assert len(serial.received) == 6 assert serial.received[:1] == SET_PI assert serial.received[1:3] == p_encoded assert serial.received[3:5] == i_encoded assert serial.received[5:] == s_encoded