forked from andrew/karung-counting-feedmill-semarang
65 lines
2.1 KiB
Python
65 lines
2.1 KiB
Python
"""Test for predict.py integration."""
|
|
|
|
|
|
from src.pipeline import CountingPipeline
|
|
from src.validation import InputValidator
|
|
|
|
|
|
def test_predict_integration():
|
|
"""Test that pipeline can be initialized and configured."""
|
|
validator = InputValidator()
|
|
assert validator.validate_video_source("rtsp://example.com") == True
|
|
|
|
pipeline = CountingPipeline("config.yaml")
|
|
assert pipeline is not None
|
|
|
|
|
|
def test_deploy_to_jetson_includes_src_modules():
|
|
"""Verify deploy_to_jetson.py syncs all refactored src modules required by predict.py."""
|
|
import deploy_to_jetson
|
|
|
|
local_files = {src for src, _ in deploy_to_jetson.files_to_sync}
|
|
for required in (
|
|
"src/pipeline.py",
|
|
"src/ui.py",
|
|
"src/persistence.py",
|
|
"src/validation.py",
|
|
"src/config_loader.py",
|
|
):
|
|
assert required in local_files, f"Missing {required} in deploy_to_jetson.files_to_sync"
|
|
|
|
|
|
def test_build_model_pipeline_loads_pt_before_engine(monkeypatch, tmp_path):
|
|
"""Verify build_model_pipeline loads PyTorch .pt models before TensorRT .engine models."""
|
|
import predict
|
|
from src.config_loader import load_config
|
|
|
|
cfg = load_config("config.yaml")
|
|
# Create dummy files so cfg.engine_path resolves them as-is
|
|
models_dir = tmp_path / "models"
|
|
models_dir.mkdir(exist_ok=True)
|
|
(models_dir / "v4-best.engine").write_bytes(b"0")
|
|
(models_dir / "box.pt").write_bytes(b"0")
|
|
|
|
cfg.models.paths["combined"] = "models/v4-best.engine"
|
|
cfg.models.paths["box"] = "models/box.pt"
|
|
|
|
loaded_order = []
|
|
|
|
class DummyYOLO:
|
|
def __init__(self, model_path):
|
|
loaded_order.append(str(model_path))
|
|
|
|
def __call__(self, *args, **kwargs):
|
|
return []
|
|
|
|
monkeypatch.setattr(predict, "YOLO", DummyYOLO)
|
|
monkeypatch.setattr(predict, "ByteTrackTracker", lambda *a, **kw: object())
|
|
monkeypatch.setattr(predict, "TruckDetector", lambda *a, **kw: object())
|
|
|
|
predict.build_model_pipeline("C", cfg, "cpu", str(tmp_path))
|
|
assert len(loaded_order) == 2
|
|
assert loaded_order[0].endswith(".pt"), f"Expected .pt loaded before .engine, got {loaded_order}"
|
|
assert loaded_order[1].endswith(".engine")
|
|
|