Esempio n. 1
0
def test_stop_buzzer():
    serial = MockSerial(ACK)
    attiny = AttinyProtocol(serial)
    result = attiny.stop_buzzer()

    assert result == True
    assert serial.received == STOP_BUZZER
Esempio n. 2
0
def test_set_left_motor_timeout():
    serial = MockSerial(b'')

    attiny = AttinyProtocol(serial)
    result = attiny.set_left_motor(0)

    assert result == False
Esempio n. 3
0
def test_set_left_motor_nak():
    serial = MockSerial(NAK)

    attiny = AttinyProtocol(serial)
    result = attiny.set_left_motor(0)

    assert result == False
Esempio n. 4
0
def test_set_both_motors_timeout():
    serial = MockSerial(b'')

    attiny = AttinyProtocol(serial)
    result = attiny.set_motors(0, 0)

    assert result == False
Esempio n. 5
0
def test_set_both_motors_nak():
    serial = MockSerial(NAK)

    attiny = AttinyProtocol(serial)
    result = attiny.set_motors(0, 0)

    assert result == False
Esempio n. 6
0
def test_reset_both_encoders_invalid():
    serial = MockSerial(INVALID_RESPONSE)
    attiny = AttinyProtocol(serial)

    with pytest.raises(InvalidResponseException):
        attiny.reset_encoders()

    assert serial.received == ENCODERS_RESET_BOTH
Esempio n. 7
0
def test_reset_both_encoders_timeout():
    serial = MockSerial(b'')
    attiny = AttinyProtocol(serial)

    result = attiny.reset_encoders()

    assert serial.received == ENCODERS_RESET_BOTH
    assert result == False
Esempio n. 8
0
def test_reset_left_encoder_timeout():
    serial = MockSerial(b'')
    attiny = AttinyProtocol(serial)

    result = attiny.reset_left_encoder()

    assert serial.received == ENCODERS_RESET_LEFT
    assert result == False
Esempio n. 9
0
def test_reset_right_encoder_nak():
    serial = MockSerial(NAK)
    attiny = AttinyProtocol(serial)

    result = attiny.reset_right_encoder()

    assert serial.received == ENCODERS_RESET_RIGHT
    assert result == False
Esempio n. 10
0
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
Esempio n. 11
0
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
Esempio n. 12
0
def test_set_right_motor_invalid():
    serial = MockSerial(INVALID_RESPONSE)

    attiny = AttinyProtocol(serial)
    with pytest.raises(InvalidResponseException):
        attiny.set_right_motor(0)

    assert serial.received[:1] == SET_RIGHT_MOTOR
Esempio n. 13
0
def test_reset_left_encoder():
    serial = MockSerial(ACK)
    attiny = AttinyProtocol(serial)

    result = attiny.reset_left_encoder()

    assert serial.received == ENCODERS_RESET_LEFT
    assert result == True
Esempio n. 14
0
def test_stop_motors():
    serial = MockSerial(ACK)

    attiny = AttinyProtocol(serial)
    result = attiny.stop_motors()

    assert serial.received == STOP_MOTORS

    assert result == True
Esempio n. 15
0
def test_alive_ack():
    # send out an ACK byte
    serial = MockSerial(ACK)

    attiny = AttinyProtocol(serial)
    result = attiny.alive()

    assert serial.received == ALIVE
    assert result == True
Esempio n. 16
0
def test_alive_nak():
    # send out an NAK byte
    serial = MockSerial(NAK)

    attiny = AttinyProtocol(serial)
    result = attiny.alive()

    assert serial.received == ALIVE
    assert result == False
Esempio n. 17
0
def test_echo():
    serial = MockSerial(ECHO_TEST)

    attiny = AttinyProtocol(serial)

    response = attiny.echo(ECHO_TEST)

    assert serial.received == ECHO + ECHO_TEST
    assert response == ECHO_TEST
Esempio n. 18
0
def test_stop_motors_undefined():
    # send out something that is neither an ACK or a NAK byte
    serial = MockSerial(INVALID_RESPONSE)

    attiny = AttinyProtocol(serial)
    with pytest.raises(InvalidResponseException):
        attiny.stop_motors()

    assert serial.received == STOP_MOTORS
Esempio n. 19
0
def test_stop_motors_timeout():
    serial = MockSerial(b'')

    attiny = AttinyProtocol(serial)
    result = attiny.stop_motors()

    assert serial.received == STOP_MOTORS

    assert result == False
Esempio n. 20
0
def test_echo_too_long():
    serial = MockSerial(b'')

    attiny = AttinyProtocol(serial)

    with pytest.raises(InvalidLengthException):
        attiny.echo(b'abcd')

    assert serial.received == b''
Esempio n. 21
0
def test_echo_invalid():
    serial = MockSerial(ECHO_INVALID)

    attiny = AttinyProtocol(serial)

    with pytest.raises(InvalidResponseException):
        attiny.echo(ECHO_TEST)

    assert serial.received == ECHO + ECHO_TEST
Esempio n. 22
0
def test_get_right_encoder():
    value = 21845
    encoder_bytes = value.to_bytes(2, 'big')
    serial = MockSerial(encoder_bytes)

    attiny = AttinyProtocol(serial)
    result = attiny.get_right_encoder()

    assert serial.received == ENCODERS_RIGHT
    assert result == value
Esempio n. 23
0
def test_get_left_encoder():
    value = 43690
    encoder_bytes = value.to_bytes(2, 'big')
    serial = MockSerial(encoder_bytes)

    attiny = AttinyProtocol(serial)
    result = attiny.get_left_encoder()

    assert serial.received == ENCODERS_LEFT
    assert result == value
Esempio n. 24
0
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
Esempio n. 25
0
def test_set_left_motor_zero():
    serial = MockSerial(ACK)

    left = MOTOR_ZERO
    left_bytes = BYTES_MOTOR_ZERO

    attiny = AttinyProtocol(serial)
    result = attiny.set_left_motor(left)

    assert len(serial.received) == 2
    assert serial.received == SET_LEFT_MOTOR + left_bytes

    assert result == True
Esempio n. 26
0
def test_set_right_motor_zero():
    serial = MockSerial(ACK)

    right = MOTOR_ZERO
    right_bytes = BYTES_MOTOR_ZERO

    attiny = AttinyProtocol(serial)
    result = attiny.set_right_motor(right)

    assert len(serial.received) == 2
    assert serial.received == SET_RIGHT_MOTOR + right_bytes

    assert result == True
Esempio n. 27
0
def test_set_buzzer_max():
    serial = MockSerial(ACK)
    attiny = AttinyProtocol(serial)

    result = attiny.set_buzzer(FREQUENCY_MAX, DURATION_MAX, VOLUME_MAX)

    assert result == True

    assert len(serial.received) == 6
    assert serial.received[:1] == SET_BUZZER
    assert serial.received[1:3] == FREQUENCY_MAX_ENCODED
    assert serial.received[3:5] == DURATION_MAX_ENCODED
    assert serial.received[5:] == VOLUME_MAX_ENCODED
Esempio n. 28
0
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
Esempio n. 29
0
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
Esempio n. 30
0
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