digitalio

A mock of the digitalio module.

from circuitpython_mocks import board
from circuitpython_mocks.digitalio import DigitalInOut, Direction, DriveMode, Pull
from circuitpython_mocks.digitalio.operations import SetState, GetState


def test_dio():
    with DigitalInOut(board.D42) as dio:
        assert dio.direction == Direction.INPUT
        assert dio.pull is None

        # set expectations for the pin state changes
        dio.expectations.append(GetState(True))
        assert dio.value
        dio.expectations.extend([SetState(False), SetState(True)])
        dio.switch_to_output()
        dio.value = True

        # assert all expectation were used
        dio.done()
class circuitpython_mocks.digitalio.DigitalInOut(pin: Pin, **kwargs)[source]

A class that mocks :external:py:class:digitalio.DigitalInOut`

deinit()[source]

Deinitialize the Digital Pin

property direction : Direction

Get or Set the Digital Pin Direction

property drive_mode : DriveMode

The Digital Pin Drive Mode

property pull : Pull | None

The pin pull direction

switch_to_input(pull: Pull | None = None)[source]

Switch the Digital Pin Mode to Input

switch_to_output(value: bool | int = False, drive_mode: DriveMode = DriveMode.PUSH_PULL)[source]

Switch the Digital Pin Mode to Output.

Mock Expectations

This function also changes the state of the pin’s value. So, this function will check against SetState expectations.

property value : bool | int

The Digital Pin Value.

Mock Expectations

This property will check against SetState and GetState expectations.

class circuitpython_mocks.digitalio.Direction

A mock enumeration of digitalio.Direction.

INPUT : Direction
OUTPUT : Direction
class circuitpython_mocks.digitalio.DriveMode

A mock enumeration of digitalio.DriveMode.

PUSH_PULL : DriveMode
OPEN_DRAIN : DriveMode
class circuitpython_mocks.digitalio.Pull

A mock enumeration of digitalio.Pull.

UP : Pull
DOWN : Pull

digitalio.operations

class circuitpython_mocks.digitalio.operations.SetState(state: bool | int)[source]

A class to represent setting the state of a DigitalInOut pin.

class circuitpython_mocks.digitalio.operations.GetState(state: bool | int)[source]

A class to represent getting the state of a DigitalInOut pin.