Skip to content

Add s7 unified client/server tests, fix mypy issues#691

Merged
gijzelaerr merged 1 commit into
masterfrom
test/s7-client-coverage
Apr 15, 2026
Merged

Add s7 unified client/server tests, fix mypy issues#691
gijzelaerr merged 1 commit into
masterfrom
test/s7-client-coverage

Conversation

@gijzelaerr
Copy link
Copy Markdown
Owner

Summary

The s7 package (unified client/server) had zero direct tests — everything was tested through snap7. This adds 24 tests using the built-in server emulator.

Coverage improvements:

  • s7/client.py: 21% → 77%
  • s7/server.py: 43% → 84%
  • Total: 78% → 79%
  • mypy: 0 errors (was 7)

Tests added:

  • Legacy protocol: connect, db_read, db_write, db_read_multi, list_datablocks, context manager, repr, delegated methods, diagnostic buffer
  • S7CommPlus guards: browse/explore/subscription require S7CommPlus connection
  • Server: context manager, register_db, register_raw_db, get_db, properties
  • Protocol enum

Also fixes unused type: ignore comments and missing import in test_logging.py.

Test plan

  • 1465 tests pass (24 new)
  • mypy clean (0 errors across 79 files)
  • ruff clean

🤖 Generated with Claude Code

@gijzelaerr gijzelaerr added this to the 4.0 milestone Apr 15, 2026
@gijzelaerr gijzelaerr force-pushed the test/s7-client-coverage branch from 28b271b to 6a9842c Compare April 15, 2026 11:49
32 tests for s7.Client and s7.Server using the built-in emulators:

- Legacy: connect, db_read, db_write, db_read_multi, list_datablocks,
  context manager, delegated methods, diagnostic buffer
- S7CommPlus: connect, db_read, db_write, db_read_multi, explore,
  list_datablocks, browse, browse-to-SymbolTable, auto-detection
- Server: context manager, register_db/raw_db, get_db, properties
- Guard tests: browse/explore/subscription require S7CommPlus

Bug fixes:
- s7/client.py: legacy connection optional when S7CommPlus explicit
- s7/_s7commplus_client.py: EXPLORE parser handles WSTRING (0x15),
  UDINT (0x04) datatypes, skips return code VLQ, tracks nesting depth
  to avoid child objects overwriting parent DB name/number
- s7/_s7commplus_server.py: EXPLORE response uses standard S7CommPlus
  IDs (Ids.OBJECT_VARIABLE_TYPE_NAME, Ids.BLOCK_BLOCK_NUMBER) with
  proper flags+datatype encoding

Coverage: s7/client.py 21%→88%, s7/_s7commplus_client.py 40%→67%,
total 78%→81%. mypy clean (0 errors across 79 files).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gijzelaerr gijzelaerr force-pushed the test/s7-client-coverage branch from 6a9842c to ea259b9 Compare April 15, 2026 12:09
@gijzelaerr gijzelaerr merged commit 2d95589 into master Apr 15, 2026
38 of 39 checks passed
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