Skip to content

Conversation

Copy link

Copilot AI commented Oct 6, 2025

This PR adds comprehensive unit tests for the pure Python implementations in the snap7/low_level/ directory, specifically for s7_client.py, s7_server.py, and s7_partner.py.

Overview

The low_level directory contains native Python implementations of the S7 protocol (similar to Sharp7), which provide an alternative to the C library wrapper. These implementations previously lacked dedicated unit tests.

Changes

New Test Files

  1. tests/test_low_level_s7_client.py - 11 tests covering:

    • S7Client initialization and configuration
    • Connection parameter setup (set_connection_params)
    • Parameter management (get_param, set_param)
    • Helper classes (S7SZL, S7SZLHeader)
    • Basic operations (disconnect, get_last_error, get_exec_time)
  2. tests/test_low_level_s7_server.py - 12 tests covering:

    • S7Server initialization and state management
    • Memory area registration/unregistration
    • Server status retrieval and CPU state management
    • Start/stop operations on custom ports
    • Parameter configuration
    • Event callback setup
  3. tests/test_low_level_s7_partner.py - 20 tests covering:

    • S7Partner initialization (both active and passive modes)
    • Lifecycle management (create, start, stop, destroy)
    • Asynchronous operation completion checking
    • Parameter management and statistics retrieval
    • Send/receive buffer operations
    • Callback configuration

Configuration Updates

  • Updated pyproject.toml to add pytest markers for the new test modules: low_level_client, low_level_server, low_level_partner

Test Coverage

All 43 new tests pass successfully and cover:

  • Core functionality of the pure Python S7 implementations
  • Initialization and configuration
  • State management and lifecycle operations
  • Parameter handling
  • Buffer and callback management
  • Error handling

The tests are designed to run without requiring an actual PLC connection or the native snap7 library, making them suitable for CI/CD pipelines and local development.

Testing

# Run all low_level tests
pytest tests/test_low_level_*.py -v

# Run specific module tests
pytest tests/test_low_level_s7_client.py -v
pytest tests/test_low_level_s7_server.py -v
pytest tests/test_low_level_s7_partner.py -v

Fixes #[issue_number]

Original prompt

Ok, add the unit test in folder test for low_level/ S7_client and s7_server and s7_partner.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…ules

Co-authored-by: lupaulus <20111917+lupaulus@users.noreply.github.com>
Copilot AI changed the title [WIP] Ok, add the unit test in folder test for low_level/ S7_client and s7_server and s7_partner. Add unit tests for low_level S7Client, S7Server, and S7Partner modules Oct 6, 2025
Copilot AI requested a review from lupaulus October 6, 2025 19:42
Copilot finished work on behalf of lupaulus October 6, 2025 19:42
@lupaulus lupaulus marked this pull request as ready for review October 7, 2025 12:33
@lupaulus lupaulus merged commit 73b871e into native_python Oct 7, 2025
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.

2 participants