| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- """control_mock example must default to mock and refuse a real endpoint without the flag."""
- from __future__ import annotations
- import os
- import subprocess
- import sys
- from pathlib import Path
- SDK_ROOT = Path(__file__).resolve().parents[1]
- EXAMPLES = SDK_ROOT / "examples"
- def _python() -> str:
- # Isolated wheel/venv tests must use the interpreter running pytest.
- # Do not prefer /data/prod2u/bin/python3: that wrapper can exec a
- # different libexec python and fail to open the example script.
- return sys.executable
- def _env() -> dict[str, str]:
- env = os.environ.copy()
- if (SDK_ROOT / "hth_sdk").is_dir():
- env["PYTHONPATH"] = str(SDK_ROOT) + os.pathsep + env.get("PYTHONPATH", "")
- return env
- def test_control_mock_runs_without_daemon():
- proc = subprocess.run(
- [ _python(), str(EXAMPLES / "control_mock.py")],
- check=False,
- capture_output=True,
- text=True,
- timeout=20,
- env=_env(),
- )
- assert proc.returncode == 0, proc.stdout + proc.stderr
- assert "UNCONFIRMED" in proc.stdout
- assert "FULL OPEN" in proc.stdout
- def test_control_mock_refuses_real_endpoint_without_flag():
- proc = subprocess.run(
- [
- _python(),
- str(EXAMPLES / "control_mock.py"),
- "--allow-real-endpoint",
- "/run/hth/control.sock",
- ],
- check=False,
- capture_output=True,
- text=True,
- timeout=10,
- env=_env(),
- )
- assert proc.returncode == 2
- assert "refusing real endpoint" in proc.stderr
|