hx870
hx870 copied to clipboard
Implement device simulator for testing
The device protocol is sufficiently well-understood by now that we can write a protocol-level HX device emulator to run implementation tests against.
This should be a good weekend's day of work.
The ultimate goal should be to mock low-level reads and writes in the serial
module to enable full-stack testing of our code, but that would take some major figuring unless someone's experienced with mocking that module in particular already.
A more achievable first step for noobs like us would be to implement an hxtool.tty.GenericHXTTYSimulator
shim as replacement for hxtool.tty.GenericHXTTY
in tests.
We maaaay even be able to hot-patch hxtool.tty.GenericHXTTY
functions in memory, but that requires some investigation and playfulness.
The simulator should also be exposed as a hidden model that automatically shows up in the device enumeration if activated by a global --simulator
argument, for example.
Found a neat way to implement the simulator as a virtual pseudo device that Python's serial module can talk to in place of a regular serial device. Implemented a stub (see hxtool --simulator devices
) and a test harness for it. So far the simulator will make hxtool throw ProtocolError on any config write attempt, but at least the current architecture is paving the way for a more complete implementation.
The simulator, even in its current, incomplete state, already enables a number of module and integration tests.