Add tests to improve coverage from 78% to 84%#642
Merged
gijzelaerr merged 2 commits intomasterfrom Mar 20, 2026
Merged
Conversation
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>
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
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 pathstests/test_server_cli.py— Click CLI entrypoint (--help, --version)tests/test_s7protocol_coverage.py— S7Protocol response parsers with crafted PDUstests/test_db_coverage.py— DB/Row dict interface, read/write with mocked client, all type conversionsTest plan
uv run pytest tests/ --ignore=tests/test_s7commplus_e2e.py)uv run mypy snap7)uv run ruff check snap7 tests/)uv run ruff format --check snap7 tests/)🤖 Generated with Claude Code