Exemple #1
0
def test_required_pin_modes() -> None:
    """Test the runtime check for required pin modes."""
    driver = MockGPIOPinDriver()
    pin = GPIOPin(
        0,
        driver,
        initial_mode=GPIOPinMode.DIGITAL_OUTPUT,
        hardware_modes={
            GPIOPinMode.DIGITAL_OUTPUT,
            GPIOPinMode.DIGITAL_INPUT,
        },
    )

    # 0
    pin._require_pin_modes([])

    # 1
    pin._require_pin_modes([GPIOPinMode.DIGITAL_OUTPUT])

    with pytest.raises(BadGPIOPinModeError):
        pin._require_pin_modes([GPIOPinMode.DIGITAL_INPUT_PULLUP])

    # 2
    pin._require_pin_modes([
        GPIOPinMode.DIGITAL_OUTPUT,
        GPIOPinMode.DIGITAL_INPUT,
    ])
Exemple #2
0
def test_required_pin_modes():
    """Test the runtime check for required pin modes."""
    driver = MockGPIOPinDriver()
    pin = GPIOPin(
        0,
        MockGPIOPinBoard(),
        driver,
        supported_modes=[
            GPIOPinMode.DIGITAL_OUTPUT,
            GPIOPinMode.DIGITAL_INPUT,
        ],
    )

    # 0
    pin._require_pin_modes([])

    # 1
    pin._require_pin_modes([GPIOPinMode.DIGITAL_OUTPUT])

    with pytest.raises(BadGPIOPinModeError):
        pin._require_pin_modes([GPIOPinMode.DIGITAL_INPUT_PULLUP])

    # 2
    pin._require_pin_modes([
        GPIOPinMode.DIGITAL_OUTPUT,
        GPIOPinMode.DIGITAL_INPUT,
    ])