Exemple #1
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
Exemple #2
0
def test_set_buzzer_inrange():
    serial = MockSerial(ACK)
    attiny = AttinyProtocol(serial)

    frequency = 440
    duration = 1000
    volume = 7

    result = attiny.set_buzzer(frequency, duration, volume)

    assert result == True

    assert len(serial.received) == 6
    assert serial.received[:1] == SET_BUZZER
    assert serial.received[1:3] == frequency.to_bytes(2, 'big')
    assert serial.received[3:5] == duration.to_bytes(2, 'big')
    assert serial.received[5:] == volume.to_bytes(1, 'big')
Exemple #3
0
def test_set_buzzer_invalid():
    serial = MockSerial(INVALID_RESPONSE)
    attiny = AttinyProtocol(serial)

    with pytest.raises(InvalidResponseException):
        attiny.set_buzzer(0, 0, 0)
Exemple #4
0
def test_set_buzzer_timeout():
    serial = MockSerial(b'')
    attiny = AttinyProtocol(serial)
    result = attiny.set_buzzer(0, 0, 0)

    assert result == False
Exemple #5
0
def test_set_buzzer_nak():
    serial = MockSerial(NAK)
    attiny = AttinyProtocol(serial)
    result = attiny.set_buzzer(0, 0, 0)

    assert result == False