The test suite is split into small, deterministic unit tests and a narrower integration layer for socket-backed protocol paths. The current harness is designed to run in the local development environment, in CI, and in restricted sandboxes without changing the test code.
- Unit tests
- Fast tests that exercise packet helpers, file-format parsers, and client logic with fake transports or in-memory fixtures. These are the default regression tests and should stay deterministic.
- Integration tests
- Tests that need a listening socket or more realistic transport behavior.
They are marked with
integrationand are skipped automatically when the environment cannot bind sockets.
The current test coverage is centered on these modules:
tests/fields_test.pycovers reusable field helpers inpysap.utils.fields.tests/sapsnc_test.pycovers SNC frame wrapping and unwrapping logic.tests/saplps_test.pycovers the LPS cipher dispatch and error paths.tests/sapdiagclient_test.pycovers client setup, send/receive flow, and support-data normalization.tests/sapenqueue_test.pycovers enqueue packet helpers and stream reassembly.tests/sapigs_test.pycovers IGS packet construction and request helpers.tests/sapms_test.pycovers representative message-server packet types.tests/saprfc_test.pycovers RFC packet variants and field handling.tests/sapcar_test.py,tests/sapcredv2_test.py,tests/sappse_test.py, andtests/sapssfs_test.pycover the file-format and crypto-oriented paths.tests/sapdiag_test.py,tests/sapni_test.py,tests/saprouter_test.py, andtests/saphdb_test.pycover protocol packet handling, with the socket heavy cases marked as integration.
The test harness uses tests/conftest.py to keep collection stable across
environments. It disables Scapy interface probing during test discovery and
skips integration-marked tests when socket binding is not available.
Shared helpers live in tests/utils.py. The current helpers provide packet
round-trip checks and a dummy connection object for tests that only need to
exercise protocol logic.
Run the core lint suite with tox:
$ python3 -m tox -e lint-core
Run the examples lint suite separately:
$ python3 -m tox -e lint-examples
Run the full unit suite with tox:
$ python3 -m tox -e unit
Run the integration suite separately:
$ python3 -m tox -e integration
If you are iterating on a single module, pytest can target it directly:
$ python3 -m pytest tests/saplps_test.py
Keep new tests at the smallest useful scope. Prefer fake sockets, small packet fixtures, and round-trip assertions over live network dependencies unless the behavior truly requires them.
Good additions usually follow these rules:
- one behavior per test;
- deterministic inputs and outputs;
- negative-path coverage for invalid versions, malformed fields, and error handling;
- integration markers only for code that must bind sockets or talk to a live service.
Coverage tends to improve fastest when tests focus on helper functions and packet builders first, then move outward to transport wrappers and socket-backed flows.