From 22c479027f81d7eb38953fbaf143382622141ff5 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Mon, 5 Aug 2024 20:23:53 -0700 Subject: [PATCH] review docs --- circuitpython_mocks/digitalio/__init__.py | 26 +++++++++------- docs/board.rst | 1 - docs/busio.rst | 17 +++++++++- docs/conf.py | 7 ++++- docs/digitalio.rst | 38 +++++++++++++++++++++-- 5 files changed, 73 insertions(+), 16 deletions(-) diff --git a/circuitpython_mocks/digitalio/__init__.py b/circuitpython_mocks/digitalio/__init__.py index 487c72f..1cd455f 100644 --- a/circuitpython_mocks/digitalio/__init__.py +++ b/circuitpython_mocks/digitalio/__init__.py @@ -1,5 +1,5 @@ from enum import Enum, auto - +from typing import Union, Optional from circuitpython_mocks._mixins import ContextManaged, Expecting from circuitpython_mocks.digitalio.operations import GetState, SetState from circuitpython_mocks.board import Pin @@ -34,13 +34,17 @@ def __init__(self, pin: Pin, **kwargs): self._pin = pin self.switch_to_input() - def switch_to_output(self, value=False, drive_mode=DriveMode.PUSH_PULL): + def switch_to_output( + self, + value: Union[bool, int] = False, + drive_mode: DriveMode = DriveMode.PUSH_PULL, + ): """Switch the Digital Pin Mode to Output""" self.direction = Direction.OUTPUT self.value = value self.drive_mode = drive_mode - def switch_to_input(self, pull=None): + def switch_to_input(self, pull: Optional[Pull] = None): """Switch the Digital Pin Mode to Input""" self.direction = Direction.INPUT self.pull = pull @@ -50,12 +54,12 @@ def deinit(self): del self._pin @property - def direction(self): + def direction(self) -> Direction: """Get or Set the Digital Pin Direction""" return self.__direction @direction.setter - def direction(self, value): + def direction(self, value: Direction): self.__direction = value if value == Direction.OUTPUT: # self.value = False @@ -66,7 +70,7 @@ def direction(self, value): raise AttributeError("Not a Direction") @property - def value(self): + def value(self) -> Union[bool, int]: """The Digital Pin Value. This property will check against `SetState` and `GetState` :py:attr:`~circuitpython_mocks._mixins.Expecting.expectations`.""" @@ -78,7 +82,7 @@ def value(self): return op.state @value.setter - def value(self, val): + def value(self, val: Union[bool, int]): if self.direction != Direction.OUTPUT: raise AttributeError("Not an output") assert self.expectations, "No expectations found for DigitalInOut.value.setter" @@ -89,25 +93,25 @@ def value(self, val): op.assert_state(val) @property - def pull(self): + def pull(self) -> Optional[Pull]: """The pin pull direction""" if self.direction == Direction.INPUT: return self.__pull raise AttributeError("Not an input") @pull.setter - def pull(self, pul): + def pull(self, pul: Optional[Pull]): if self.direction != Direction.INPUT: raise AttributeError("Not an input") self.__pull = pul @property - def drive_mode(self): + def drive_mode(self) -> DriveMode: """The Digital Pin Drive Mode""" if self.direction != Direction.OUTPUT: raise AttributeError("Not an output") return self.__drive_mode @drive_mode.setter - def drive_mode(self, mod): + def drive_mode(self, mod: DriveMode): self.__drive_mode = mod diff --git a/docs/board.rst b/docs/board.rst index 63ad627..20c9796 100644 --- a/docs/board.rst +++ b/docs/board.rst @@ -3,7 +3,6 @@ .. automodule:: circuitpython_mocks.board :members: - :undoc-members: This module includes the following dummy pins for soft-testing: diff --git a/docs/busio.rst b/docs/busio.rst index 3665683..328770e 100644 --- a/docs/busio.rst +++ b/docs/busio.rst @@ -2,7 +2,22 @@ ================= .. automodule:: circuitpython_mocks.busio - :members: + + .. autoclass:: circuitpython_mocks.busio.I2C + :members: __init__, readfrom_into, writeto, writeto_then_readfrom, scan + .. autoclass:: circuitpython_mocks.busio.SPI + :members: __init__, readinto, write, write_readinto, configure, frequency + .. autoclass:: circuitpython_mocks.busio.UART + :members: __init__, readinto, readline, write + + .. py:class:: circuitpython_mocks.busio.UART.Parity + + A mock enumeration of :external:py:class:`busio.Parity`. + + .. py:attribute:: ODD + :type: Parity + .. py:attribute:: EVEN + :type: Parity ``busio.operations`` -------------------- diff --git a/docs/conf.py b/docs/conf.py index 3b86a1f..aeb04c9 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -22,7 +22,11 @@ "sphinx.ext.intersphinx", "sphinx_jinja", ] + autodoc_class_signature = "separated" +autodoc_default_options = { + "exclude-members": "__new__", +} templates_path = ["_templates"] exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] @@ -32,7 +36,7 @@ "pins": [ x for x in dir(circuitpython_mocks.board) - if not x.startswith("_") and x != "Pin" + if not x.startswith("_") and x not in ("Pin", "board_id") ] } } @@ -63,6 +67,7 @@ "features": [ "navigation.top", "search.share", + "toc.follow", ], "palette": [ { diff --git a/docs/digitalio.rst b/docs/digitalio.rst index 46f1072..4907060 100644 --- a/docs/digitalio.rst +++ b/docs/digitalio.rst @@ -2,10 +2,44 @@ ================= .. automodule:: circuitpython_mocks.digitalio - :members: + + .. autoclass:: circuitpython_mocks.digitalio.DigitalInOut + :members: value, deinit, direction, drive_mode, pull, switch_to_input, switch_to_output + + .. py:class:: circuitpython_mocks.digitalio.Direction + + A mock enumeration of :external:py:class:`digitalio.Direction`. + + .. py:attribute:: INPUT + :type: Direction + .. py:attribute:: OUTPUT + :type: Direction + + .. py:class:: circuitpython_mocks.digitalio.DriveMode + + A mock enumeration of :external:py:class:`digitalio.DriveMode`. + + .. py:attribute:: PUSH_PULL + :type: DriveMode + .. py:attribute:: OPEN_DRAIN + :type: DriveMode + + .. py:class:: circuitpython_mocks.digitalio.Pull + + A mock enumeration of :external:py:class:`digitalio.Pull`. + + .. py:attribute:: UP + :type: Pull + .. py:attribute:: DOWN + :type: Pull + ``digitalio.operations`` ------------------------ .. automodule:: circuitpython_mocks.digitalio.operations - :members: + + .. autoclass:: circuitpython_mocks.digitalio.operations.SetState + :members: __init__ + .. autoclass:: circuitpython_mocks.digitalio.operations.GetState + :members: __init__