コード例 #1
0
def test_is_toggle(arduino: Mock, led: DimmableLED) -> None:
    led.toggle()
    led.toggle()
    assert arduino.analog_write.call_args_list == [
        call(PIN_NUM, 0, TOKEN),
        call(PIN_NUM, 255, TOKEN),
        call(PIN_NUM, 0, TOKEN),
    ]
コード例 #2
0
def test_brightness_when_on(arduino: Mock, led: DimmableLED) -> None:
    led.turn_on()
    led.brightness = 100
    assert arduino.analog_write.call_args_list == [
        call(PIN_NUM, 0, TOKEN),
        call(PIN_NUM, 255, TOKEN),
        call(PIN_NUM, 100, TOKEN),
    ]
    assert led.brightness == 100
コード例 #3
0
def test_non_default_brightness_is_set_when_turning_on(
    arduino: Mock, led: DimmableLED
) -> None:
    led.brightness = 100
    led.turn_on()
    assert arduino.analog_write.call_args_list == [
        call(PIN_NUM, 0, TOKEN),
        call(PIN_NUM, 100, TOKEN),
    ]
    assert led.brightness == 100
コード例 #4
0
def test_is_on(arduino: Mock, led: DimmableLED) -> None:
    assert led.is_on() is False
    led.turn_on()
    assert led.is_on() is True
コード例 #5
0
def test_turn_off(arduino: Mock, led: DimmableLED) -> None:
    led.turn_off()
    assert arduino.analog_write.call_args_list == [
        call(PIN_NUM, 0, TOKEN),
        call(PIN_NUM, 0, TOKEN),
    ]
コード例 #6
0
def led(arduino: Arduino) -> DimmableLED:
    return DimmableLED(arduino, PIN_NUM)