1- """A module to mock the data bus transactions."""
1+ """A mock of the :external:py:mod:`busio` module.
2+
3+ .. md-tab-set::
4+
5+ .. md-tab-item:: I2C
6+
7+ .. literalinclude:: ../tests/test_i2c.py
8+ :language: python
9+
10+ .. md-tab-item:: SPI
11+
12+ .. literalinclude:: ../tests/test_spi.py
13+ :language: python
14+
15+ .. md-tab-item:: UART
16+
17+ .. literalinclude:: ../tests/test_uart.py
18+ :language: python
19+ """
220
321from enum import Enum , auto
422import sys
@@ -77,8 +95,12 @@ def readfrom_into(
7795 end : int = sys .maxsize ,
7896 ) -> None :
7997 """A mock imitation of :external:py:meth:`busio.I2C.readfrom_into()`.
80- This function checks against `I2CRead`
81- :py:attr:`~circuitpython_mocks._mixins.Expecting.expectations`"""
98+
99+ .. mock-expects::
100+
101+ This function checks against `I2CRead`
102+ :py:attr:`~circuitpython_mocks._mixins.Expecting.expectations`.
103+ """
82104 assert self .expectations , "no expectation found for I2C.readfrom_into()"
83105 op = self .expectations .popleft ()
84106 assert isinstance (op , I2CRead ), f"Read operation expected, found { repr (op )} "
@@ -95,8 +117,12 @@ def writeto(
95117 end : int = sys .maxsize ,
96118 ) -> None :
97119 """A mock imitation of :external:py:meth:`busio.I2C.writeto()`.
98- This function checks against `I2CWrite`
99- :py:attr:`~circuitpython_mocks._mixins.Expecting.expectations`"""
120+
121+ .. mock-expects::
122+
123+ This function checks against `I2CWrite`
124+ :py:attr:`~circuitpython_mocks._mixins.Expecting.expectations`.
125+ """
100126 assert self .expectations , "no expectation found for I2C.writeto()"
101127 op = self .expectations .popleft ()
102128 assert isinstance (op , I2CWrite ), f"Read operation expected, found { repr (op )} "
@@ -115,8 +141,12 @@ def writeto_then_readfrom(
115141 in_end : int = sys .maxsize ,
116142 ) -> None :
117143 """A mock imitation of :external:py:meth:`busio.I2C.writeto_then_readfrom()`.
118- This function checks against `I2CTransfer`
119- :py:attr:`~circuitpython_mocks._mixins.Expecting.expectations`"""
144+
145+ .. mock-expects::
146+
147+ This function checks against `I2CTransfer`
148+ :py:attr:`~circuitpython_mocks._mixins.Expecting.expectations`.
149+ """
120150 assert self .expectations , "no expectation found for I2C.writeto_then_readfrom()"
121151 op = self .expectations .popleft ()
122152 assert isinstance (
@@ -180,8 +210,12 @@ def write(
180210 end : int = sys .maxsize ,
181211 ) -> None :
182212 """A function that mocks :external:py:meth:`busio.SPI.write()`.
183- This function checks against `SPIWrite`
184- :py:attr:`~circuitpython_mocks._mixins.Expecting.expectations`"""
213+
214+ .. mock-expects::
215+
216+ This function checks against `SPIWrite`
217+ :py:attr:`~circuitpython_mocks._mixins.Expecting.expectations`.
218+ """
185219 assert self .expectations , "no expectation found for SPI.write()"
186220 op = self .expectations .popleft ()
187221 assert isinstance (op , SPIWrite ), f"Read operation expected, found { repr (op )} "
@@ -196,8 +230,12 @@ def readinto(
196230 write_value : int = 0 ,
197231 ) -> None :
198232 """A function that mocks :external:py:meth:`busio.SPI.readinto()`.
199- This function checks against `SPIRead`
200- :py:attr:`~circuitpython_mocks._mixins.Expecting.expectations`"""
233+
234+ .. mock-expects::
235+
236+ This function checks against `SPIRead`
237+ :py:attr:`~circuitpython_mocks._mixins.Expecting.expectations`.
238+ """
201239 assert self .expectations , "no expectation found for SPI.readinto()"
202240 op = self .expectations .popleft ()
203241 assert isinstance (op , SPIRead ), f"Read operation expected, found { repr (op )} "
@@ -214,8 +252,12 @@ def write_readinto(
214252 in_end : int = sys .maxsize ,
215253 ) -> None :
216254 """A function that mocks :external:py:meth:`busio.SPI.write_readinto()`.
217- This function checks against `SPITransfer`
218- :py:attr:`~circuitpython_mocks._mixins.Expecting.expectations`"""
255+
256+ .. mock-expects::
257+
258+ This function checks against `SPITransfer`
259+ :py:attr:`~circuitpython_mocks._mixins.Expecting.expectations`.
260+ """
219261 assert self .expectations , "no expectation found for SPI.write_readinto()"
220262 op = self .expectations .popleft ()
221263 assert isinstance (
@@ -262,8 +304,12 @@ def __init__(
262304
263305 def read (self , nbytes : int | None = None ) -> bytes | None :
264306 """A function that mocks :external:py:meth:`busio.UART.read()`.
265- This function checks against `UARTRead`
266- :py:attr:`~circuitpython_mocks._mixins.Expecting.expectations`"""
307+
308+ .. mock-expects::
309+
310+ This function checks against `UARTRead`
311+ :py:attr:`~circuitpython_mocks._mixins.Expecting.expectations`.
312+ """
267313 assert self .expectations , "no expectation found for UART.read()"
268314 op = self .expectations .popleft ()
269315 assert isinstance (op , UARTRead ), f"Read operation expected, found { repr (op )} "
@@ -274,8 +320,12 @@ def read(self, nbytes: int | None = None) -> bytes | None:
274320
275321 def readinto (self , buf : circuitpython_typing .WriteableBuffer ) -> int | None :
276322 """A function that mocks :external:py:meth:`busio.UART.readinto()`.
277- This function checks against `UARTRead`
278- :py:attr:`~circuitpython_mocks._mixins.Expecting.expectations`"""
323+
324+ .. mock-expects::
325+
326+ This function checks against `UARTRead`
327+ :py:attr:`~circuitpython_mocks._mixins.Expecting.expectations`.
328+ """
279329 assert self .expectations , "no expectation found for UART.readinto()"
280330 op = self .expectations .popleft ()
281331 assert isinstance (op , UARTRead ), f"Read operation expected, found { repr (op )} "
@@ -285,8 +335,12 @@ def readinto(self, buf: circuitpython_typing.WriteableBuffer) -> int | None:
285335
286336 def readline (self ) -> bytes :
287337 """A function that mocks :external:py:meth:`busio.UART.readline()`.
288- This function checks against `UARTRead`
289- :py:attr:`~circuitpython_mocks._mixins.Expecting.expectations`"""
338+
339+ .. mock-expects::
340+
341+ This function checks against `UARTRead`
342+ :py:attr:`~circuitpython_mocks._mixins.Expecting.expectations`.
343+ """
290344 assert self .expectations , "no expectation found for UART.readline()"
291345 op = self .expectations .popleft ()
292346 assert isinstance (op , UARTRead ), f"Read operation expected, found { repr (op )} "
@@ -297,14 +351,15 @@ def readline(self) -> bytes:
297351
298352 def write (self , buf : circuitpython_typing .ReadableBuffer ) -> int | None :
299353 """A function that mocks :external:py:meth:`busio.UART.write()`.
300- This function checks against `UARTWrite`
301- :py:attr:`~circuitpython_mocks._mixins.Expecting.expectations`"""
354+
355+ .. mock-expects::
356+
357+ This function checks against `UARTWrite`
358+ :py:attr:`~circuitpython_mocks._mixins.Expecting.expectations`.
359+ """
302360 assert self .expectations , "no expectation found for UART.write()"
303361 op = self .expectations .popleft ()
304362 assert isinstance (op , UARTWrite ), f"Read operation expected, found { repr (op )} "
305363 len_buf = len (op .expected )
306364 op .assert_expected (buf , 0 , len_buf )
307365 return len (buf ) or None
308-
309-
310- _UART = UART (TX , RX )
0 commit comments