Add unit tests for LSS master (coverage 42% → 93%)#643
Add unit tests for LSS master (coverage 42% → 93%)#643acolomb merged 7 commits intocanopen-python:masterfrom
Conversation
Add 28 unit tests covering: - Switch state global/selective commands - Node ID and bit timing configuration - Activate bit timing and store configuration - LSS address inquiry (vendor/product/revision/serial) - Timeout and error handling - Fast scan protocol - Obsolete method aliases - LssError exception
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
acolomb
left a comment
There was a problem hiding this comment.
Good stuff, thank you!
As with other modules' tests, the raw byte sequence should be compared to catch wrong constants definitions, instead of using those from the module to be tested. I reworked that accordingly and fixed some style nits. Few comments remain, please have a look.
- Remove duplicate test_send_switch_state_global_no_response_expected - Remove duplicate test_lss_address_encoding and unused struct import - Restructure imports: use 'from canopen import lss' for constants, keep class imports on one line, sort alphabetically Co-authored-by: GitHub Copilot <noreply@github.com> Tool-assisted: tests were written with AI tooling assistance
bizfsc
left a comment
There was a problem hiding this comment.
Thanks for reviewing, you are 100% correct and I also like the suggested import-style more.
Disclaimer: I used Claude Opus 4.6 to generate those tests after analysis and reviewed them manually.
So I guessed. :-) But that's fine with me as long as the result is sane and reviewed by yourself. |
Summary
Add 28 unit tests for
canopen/lss.pyto improve test coverage from 42% to 93%.Tests Added
LssErrorraised on missing responsessend_switch_state_globalbackward compatApproach
Uses
unittest.mock.MagicMockto mock the network layer. A helper method injects CAN responses duringsend_message()calls to simulate real LSS slave behavior, including only responding to commands that expect a reply per the protocol.Coverage