예제 #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
예제 #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')
예제 #3
0
def test_set_buzzer_invalid():
    serial = MockSerial(INVALID_RESPONSE)
    attiny = AttinyProtocol(serial)

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

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

    assert result == False