Skip to content

Add tests to improve coverage from 78% to 84%#642

Merged
gijzelaerr merged 2 commits intomasterfrom
test/improve-coverage-phase1
Mar 20, 2026
Merged

Add tests to improve coverage from 78% to 84%#642
gijzelaerr merged 2 commits intomasterfrom
test/improve-coverage-phase1

Conversation

@gijzelaerr
Copy link
Copy Markdown
Owner

Summary

  • Added 203 new tests across 5 new test files to improve overall code coverage from 78% to 84%
  • All tests run without a real PLC, using mocks, crafted byte sequences, and unit testing
  • Key coverage improvements:
    • snap7/error.py: 70% -> 100% (check_error, error_wrap decorator, get_error_message)
    • snap7/connection.py: 68% -> 98% (COTP parsing, socket error paths, context manager)
    • snap7/s7protocol.py: 89% -> 98% (response parsers with crafted PDUs, error paths)
    • snap7/util/db.py: 65% -> 99% (DB/Row dict-like interface, read/write with mocked client, all type branches)
    • snap7/server/__main__.py: 0% -> 62% (Click CLI help/version)

New test files

  • tests/test_error.py — exception classes, check_error(), error_wrap(), get_error_message()
  • tests/test_connection.py — ISOTCPConnection with mocked sockets, COTP CC/DT parsing, error paths
  • tests/test_server_cli.py — Click CLI entrypoint (--help, --version)
  • tests/test_s7protocol_coverage.py — S7Protocol response parsers with crafted PDUs
  • tests/test_db_coverage.py — DB/Row dict interface, read/write with mocked client, all type conversions

Test plan

  • All 650 tests pass (uv run pytest tests/ --ignore=tests/test_s7commplus_e2e.py)
  • mypy clean (uv run mypy snap7)
  • ruff check clean (uv run ruff check snap7 tests/)
  • ruff format clean (uv run ruff format --check snap7 tests/)

🤖 Generated with Claude Code

gijzelaerr and others added 2 commits March 20, 2026 08:59
Add test suites for untested code paths that don't require a real PLC:
- error.py: error routing, check_error(), error_wrap() decorator
- connection.py: socket mocking, COTP parsing, exception paths
- server/__main__.py: CLI entrypoint test
- s7protocol.py: response parser tests with crafted PDUs
- util/db.py: DB/Row type conversions, dict-like interface

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use pytest.importorskip to gracefully skip CLI tests when click
(an optional dependency) is not available in the test environment.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gijzelaerr gijzelaerr merged commit 5443402 into master Mar 20, 2026
37 checks passed
@gijzelaerr gijzelaerr added this to the 3.1 milestone Mar 24, 2026
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