Documentation for this library is hosted at https://circuitpython-mocks.rtfd.io/
This is a library of mock data structures to be used in soft-testing Circuitpython-based projects.
A library of mock data structures for soft testing CircuitPython-based projects
Home Page: https://circuitpython-mocks.rtfd.io/
License: MIT License
Documentation for this library is hosted at https://circuitpython-mocks.rtfd.io/
This is a library of mock data structures to be used in soft-testing Circuitpython-based projects.
PWM is done via pwmio.PWMOut
class.
The pulseio
module might also be relevant and similarly implemented (at a glance).
Certain functions/attributes are not present in the mock busio.UART
class:
UART.in_waiting
should attempt to read the length of bytes in the next expected operation. Note, this shall not assert that the next expected operation is of type UARTRead
.UART.reset_input_buffer()
should assert that a UARTFlush
operation is expected. Note, the UARTFlush
operation does not currently exist and should be introduced.UART.timeout
may be just a dummy attribute. None
value to the UARTRead
constructor.UART.baudrate
property should return the value given to the constructor. Note, this should be a read/write property.It seems that pytest will use the monkey_patch_sys_paths
fixture if anything is imported from circuitpython_mocks
package (from the test module). It might be better to move this fixture into a submodule instead of residing in the package's root.
Currently, there's no way to manipulate the I2C.scan()
results without using pytest.MonkeyPatch
fixture. It would be more convenient to provide a new operation in expectations
that returns a mocked result for I2c.scan()
calls.
I forgot to implement this before first release. It should be added.
FYI, board.SPI
and board.I2C
is not available for all CircuitPython boards, so I think its generally discouraged to use them despite their convenience...
The only thing i didnt like on a quick glance over the code is that you have a bazillion pin names listed on
board.py
, not really because the duplication but because you are probably missing other pin names used on some boardYou can probably do something like
__pins: dict[str, Pin] = {} def __getattr__(name: str) -> Pin: if name not in __pins: return __pins[name] = Pin() return __pins[name]
Generating pins dynamically at runtime will not work because there needs to be concrete constants declared in the board
module.
Prefer using setup.py to generate (at pkg build time) the declared pins. This may involve using a submodule and just importing __all__
from the generated submodule.
Currently, the expectations are checked that they are all used upon destruction of the mocked object. However, pytest will ignore any exception thrown by a destructor. This leaves a traceback in the pytest output about "Ignored exception" when some exceptions were not used.
let unused expectations go unchecked
pros | cons |
---|---|
The done() method can be called from the test code |
This may cause a deviation from expected behavior |
assert that done()
is called upon destruction
pros | cons |
---|---|
This serves as reminder to update the test code | This seems to have poor behavior with the monkey_patch_sys_paths fixture because it is set to autouse=True (see also #9 ) |
Because pytest manages setup and tear-down as an internal implementation detail, this is destructor approach is rather undesirable.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.