Begin testing sysfs port recognition #838
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note
This PR is broken into two commits, and should likely be reviewed one at-a-time.
f5cb780 introduces a new command,
pyserial-generate-test-asset, which can generate a JSON output of a user's sysfs-based device information, and introduces a test framework for recreating the device's sysfs filesystem as it existed on the user's device in-memory.This will help with debugging sysfs-based device recognition, as well as locking valuable information into the test suite to help evaluate future code changes.
Three devices from my own testing, representing the
usb,usb-serial, andserial-basesysfs subsystems, are now tested.323c81f updates/modernizes the code in
list_ports_linux.py, which is where the sysfs-based device recognition code lives. The code was run through pyupgrade, isort, and has had type annotations added. A cursory run of mypy was made and some issues were resolved, but type annotations are not guaranteed to be correct until more of the code has been type-annotated.This introduces the following changes:
Add a
pytest-generate-test-assetcommand.The command produces a detailed JSON output
to capture the state of a device on a system
that can be used to diagnose issues with device recognition
and can be added directly to the test suite for permanence.
This command only works on sysfs systems so far.
Add test assets generated from an Ubuntu 24.04 system
running kernel 6.14.0 with real devices plugged in.
These assets demonstrate the following subsystems:
serial-baseusbusb-serialand demonstrate globbing of the following
/devpatterns:/dev/ttyACM*/dev/ttyS*/dev/ttyUSB*Increase the code coverage
fail-undervalue to 30%.Previously the value was 20%.
mypy was run against the new CLI command and passes.
However, type annotations are not yet guaranteed
until more of the project is type annotated
and mypy is passing in CI.
Type annotations have been added to
list_ports_linux.py.The
list_ports_linux.pycode has been run through mypy.Some issues were found and fixed,
but others will require additional work.
The code has been run through pyupgrade and isort.
Device patterns (like
/dev/ttyS*) have been moved,and have been reordered to reflect which patterns have tests
and which are currently untested.
The
if __name__ == "__main__"condition has been removed.If seeing the device subsystem is valuable,
the
pyserial-portscommand can be updated for that purpose.Some typos were fixed.