56 lines
1.6 KiB
Python
56 lines
1.6 KiB
Python
"""Software-only checks for the fixed HTTP-agent offline decoder."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from tools.rf001_offline_decode import decode_offline
|
|
|
|
|
|
def test_decode_offline_forces_legacy_and_refuses_overwrite(tmp_path: Path) -> None:
|
|
repository = tmp_path / "repo"
|
|
repository.mkdir()
|
|
iq_path = tmp_path / "waveform.cs8"
|
|
truth_path = tmp_path / "truth.json"
|
|
report_path = tmp_path / "report.json"
|
|
iq_path.write_bytes(b"iq")
|
|
truth_path.write_text("{}", encoding="utf-8")
|
|
calls: list[dict[str, object]] = []
|
|
|
|
def fake_decoder(iq_file: Path, **options: object) -> dict[str, object]:
|
|
calls.append({"iq_file": iq_file, **options})
|
|
return {"crc_valid_packets": 100, "exact_packets": 100}
|
|
|
|
result = decode_offline(
|
|
repository,
|
|
iq_path,
|
|
truth_path,
|
|
report_path,
|
|
decoder=fake_decoder,
|
|
)
|
|
|
|
assert result == {"crc_valid_packets": 100, "exact_packets": 100}
|
|
assert calls == [
|
|
{
|
|
"iq_file": iq_path,
|
|
"iq_format": "cs8",
|
|
"truth_metadata_path": truth_path,
|
|
"decoder_backend": "legacy",
|
|
"capture_started_at": None,
|
|
"tx_started_at": None,
|
|
"tx_finished_at": None,
|
|
}
|
|
]
|
|
assert json.loads(report_path.read_text(encoding="utf-8")) == result
|
|
with pytest.raises(FileExistsError, match="already exists"):
|
|
decode_offline(
|
|
repository,
|
|
iq_path,
|
|
truth_path,
|
|
report_path,
|
|
decoder=fake_decoder,
|
|
)
|