Skip to content

Add unit tests for LSS master (coverage 42% → 93%)#643

Open
bizfsc wants to merge 1 commit intocanopen-python:masterfrom
bizfsc:test/lss-coverage
Open

Add unit tests for LSS master (coverage 42% → 93%)#643
bizfsc wants to merge 1 commit intocanopen-python:masterfrom
bizfsc:test/lss-coverage

Conversation

@bizfsc
Copy link
Copy Markdown

@bizfsc bizfsc commented Apr 28, 2026

Summary

Add 28 unit tests for canopen/lss.py to improve test coverage from 42% to 93%.

Tests Added

  • Switch state commands: global configuration/waiting mode, selective with match/no-match
  • Node ID configuration: set node ID, error response handling
  • Bit timing configuration: set bit timing, activate with delay
  • Store configuration: success and error responses
  • LSS address inquiry: vendor ID, product code, revision number, serial number
  • Timeout handling: verify LssError raised on missing responses
  • Fast scan: full protocol flow with binary search
  • Obsolete aliases: send_switch_state_global backward compat
  • LssError: exception instantiation and inheritance

Approach

Uses unittest.mock.MagicMock to mock the network layer. A helper method injects CAN responses during send_message() calls to simulate real LSS slave behavior, including only responding to commands that expect a reply per the protocol.

Coverage

canopen/lss.py    42% → 93%
Overall           77% → 80%

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant