31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
from pathlib import Path
|
|
|
|
|
|
SCRIPT = Path(__file__).parents[2] / "scripts" / "supervise_container_yolo_training.py"
|
|
SPEC = importlib.util.spec_from_file_location("yolo_supervisor", SCRIPT)
|
|
assert SPEC and SPEC.loader
|
|
MODULE = importlib.util.module_from_spec(SPEC)
|
|
SPEC.loader.exec_module(MODULE)
|
|
|
|
|
|
def test_training_active_requires_yolo_train_and_exact_marker(monkeypatch) -> None:
|
|
class Result:
|
|
returncode = 0
|
|
stdout = "python api.py\npython3 /opt/venv/bin/yolo train resume=/runs/v37/weights/last.pt device=0\n"
|
|
|
|
monkeypatch.setattr(MODULE.subprocess, "run", lambda *args, **kwargs: Result())
|
|
assert MODULE.training_active("geointel", "/runs/v37") is True
|
|
assert MODULE.training_active("geointel", "/runs/v38") is False
|
|
|
|
|
|
def test_container_running_fails_closed_on_inspect_error(monkeypatch) -> None:
|
|
class Result:
|
|
returncode = 1
|
|
stdout = ""
|
|
|
|
monkeypatch.setattr(MODULE.subprocess, "run", lambda *args, **kwargs: Result())
|
|
assert MODULE.container_running("missing") is False
|