Testing
The zmeventnotificationNg project has three tiers of tests:
Perl unit tests for the Event Server (
zmeventnotification.pland theZmEventNotification/*.pmmodules).Python unit / integration tests for the ML hook (
zm_detect.py,zmes_hook_helpers/*) and thetools/config utilities. These mock pyzmNg and need no models.Python end-to-end (e2e) tests that run real YOLO models through the full config-to-detection chain.
None of the tests require a running ZoneMinder instance.
Running all tests
cd zmeventnotificationNg
# Perl tests
prove -I t/lib -I . -r t/
# Python unit tests (hook + tools), no models needed
cd hook && python3 -m pytest tests/ -m "not e2e" -q && cd ..
python3 -m pytest tools/tests/ -q
# Python e2e tests (needs real pyzmNg + models, see below)
cd hook && python3 -m pytest tests/test_e2e/ -q && cd ..
Unit / integration tests
These tests mock pyzmNg and use no real models. They run anywhere:
# Perl
prove -I t/lib -I . -r t/
# Python (hook unit/integration)
pip install pytest pyyaml
cd hook && python3 -m pytest tests/ -m "not e2e" -v
# Python (tools)
python3 -m pytest tools/tests/ -v
End-to-end tests
The hook/tests/test_e2e/ directory contains tests that exercise
the full objectconfig YAML → pyzmNg detection → output chain using real
YOLO models and a real test image (bird.jpg, included in the repo).
These tests use real pyzmNg (installed as a system library, not
mocked) and call the same functions that zm_detect.py uses:
process_config() → secret substitution → Detector.from_dict() →
detector.detect() → format_detection_output().
Prerequisites:
pyzmNg importable (
pip install pyzmor from source). If pyzmNg is on a non-standard path, run pytest withPYTHONPATH=/path/to/pyzmNg.ML models at
/var/lib/zmeventnotification/models/(at least one YOLO model, e.g.yolov4/orultralytics/)Python packages:
opencv-python,numpy,shapely
Run all e2e tests:
cd hook
python3 -m pytest tests/test_e2e/ -v
Run a single test file:
python3 -m pytest tests/test_e2e/test_pattern_config.py -v
Strict mode for CI (``ZM_E2E_REQUIRE=1``)
By default the e2e suite skips when prerequisites (models, bird.jpg, or a
real pyzmNg import) are missing, so local dev runs stay green. That skip would
silently hide a regression on a CI runner that lacks the models. Set
ZM_E2E_REQUIRE=1 to turn a missing prerequisite into a hard failure
instead of a skip:
# CI: fail (do not silently skip) if models/pyzm are unavailable
ZM_E2E_REQUIRE=1 python3 -m pytest tests/test_e2e/ -q
Perl test reference
File |
What it covers |
|---|---|
|
Constant definitions |
|
|
|
|
|
Rules matching |
|
HookProcessor decision logic |
|
Hook output |
|
FCM v1 payloads: proxy + direct service-account branches, the
stacked per-event tag ( |
|
MQTT payload construction |
|
WebSocket payload construction |
|
|
|
|
|
DB tagging / user-id lookup |
|
FCM token file read/write/migrate |
|
Connection accounting |
|
MQTT initialization |
|
WebSocket message handling and ``validateAuth`` password comparison
(bcrypt |
|
Google service-account JWT / access token |
|
Version string |
|
Assorted edge cases |
|
HookProcessor fork helpers: |
Python unit / integration reference
File |
What it covers |
|---|---|
|
End-to-end |
|
|
|
|
|
Monitor/remote config loading, deep-merge, |
|
|
|
|
|
|
|
|
|
Zone import filtering (active/triggered) |
|
CLI argparse early-exits (version, missing config) |
Tools test reference
File |
What it covers |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
e2e test reference
File |
What it covers |
|---|---|
|
Full config→detect→output chain, output format, show_percent,
image in matched_data, |
|
|
|
Restrictive pattern (no matches), broad pattern (matches), specific label-only pattern |
|
High threshold demonstrably drops detections vs low, low keeps |
|
|
|
Per-monitor ml_sequence override, real zone parsing into |
|
UNION strategy (both models present), FIRST strategy (first model only) |
|
Full-image zone keeps detections, tiny zone filters all, zone with restrictive pattern |
|
JSON roundtrip validity, label-confidence correlation, bounding box coordinates valid |
Test dependencies
Tier |
Dependencies |
|---|---|
Perl |
|
Python (unit) |
|
Python (e2e) |
all of the above plus |
Pytest markers and environment
Marker / env var |
Description |
|---|---|
|
End-to-end tests requiring real pyzmNg, models, and images on disk |
|
Turn missing e2e prerequisites into a hard failure instead of a skip (use in CI) |