Add unit tests for CiA 402 profile (coverage 36% → 45%)#644
Open
bizfsc wants to merge 4 commits intocanopen-python:masterfrom
Open
Add unit tests for CiA 402 profile (coverage 36% → 45%)#644bizfsc wants to merge 4 commits intocanopen-python:masterfrom
bizfsc wants to merge 4 commits intocanopen-python:masterfrom
Conversation
Add 24 unit tests covering: - State402 enum and state decoding from statusword - Command word generation for state transitions - Next-state calculation through the state machine - Homing status evaluation - Operation mode switching and reading - TPDO callback handling for statusword updates - Lookup table consistency checks
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
acolomb
requested changes
Apr 29, 2026
Member
acolomb
left a comment
There was a problem hiding this comment.
Overall this looks nice, but much more valuable would be a simulation of actual TPDO reception.
- Remove TestBaseNode402NextState: replaced by state setter tests that exercise the public .state property via TPDO/RPDO simulation - Remove TestBaseNode402HomingStatus: replaced by TestBaseNode402Homing that calls _homing_status() with TPDO-injected statusword - Remove test_supported_bitmask_unique: standard-defined values - Remove TestBaseNode402TPDOCallback: implicitly covered by all tests using _inject_tpdo() New test classes using TPDO reception simulation: - TestBaseNode402StateTransition: full state machine transitions with _FakeRpdoVar simulating drive controlword/statusword exchange - TestBaseNode402Homing: homing status via node._homing_status() - TestBaseNode402OpMode: operation mode reading via TPDO/SDO fallback - Extended TestBaseNode402State: check_statusword and statusword SDO fallback paths
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Add 24 unit tests for
canopen/profiles/p402.pyto improve test coverage from 36% to 45%.Tests Added
State402.decode_statusword()for all defined statesIS_HOMING/HOMING_COMPLETED/HOMING_ERRORevaluationApproach
Uses a minimal
ObjectDictionarywith the required DS402 objects (0x6040 controlword, 0x6041 statusword, 0x6060/0x6061 operation mode, 0x6502 supported drives). PDO maps are mocked withunittest.mock.MagicMockto test the TPDO callback path without requiring a real CAN bus.Coverage
The remaining uncovered code is primarily in
BaseNode402methods that require a live CAN bus interaction (SDO reads/writes, NMT state changes, PDO communication).