def test_set_both_motors_invalid(): serial = MockSerial(INVALID_RESPONSE) attiny = AttinyProtocol(serial) with pytest.raises(InvalidResponseException): attiny.set_motors(0, 0) assert serial.received[:1] == SET_BOTH_MOTORS
def test_set_both_motors_exceed_maxmin(): serial = MockSerial(ACK) left = MOTOR_MAX + 1 left_bytes = BYTES_MOTOR_MAX right = MOTOR_MIN - 1 right_bytes = BYTES_MOTOR_MIN attiny = AttinyProtocol(serial) attiny.set_motors(left, right) assert len(serial.received) == 3 assert serial.received == SET_BOTH_MOTORS + left_bytes + right_bytes
def test_set_both_motors_timeout(): serial = MockSerial(b'') attiny = AttinyProtocol(serial) result = attiny.set_motors(0, 0) assert result == False
def test_set_both_motors_nak(): serial = MockSerial(NAK) attiny = AttinyProtocol(serial) result = attiny.set_motors(0, 0) assert result == False
def test_set_both_motors_zero(): serial = MockSerial(ACK) left = MOTOR_ZERO left_bytes = BYTES_MOTOR_ZERO right = MOTOR_ZERO right_bytes = BYTES_MOTOR_ZERO attiny = AttinyProtocol(serial) result = attiny.set_motors(left, right) assert len(serial.received) == 3 assert serial.received == SET_BOTH_MOTORS + left_bytes + right_bytes assert result == True