feat: scaffold cosma-log-analyzer with 5 deterministic rules + fake MCAP e2e test
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
58
tests/test_ingest.py
Normal file
58
tests/test_ingest.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from cosma_log_analyzer.ingest import (
|
||||
KNOWN_TOPICS,
|
||||
TOPIC_BATTERY,
|
||||
TOPIC_IMU,
|
||||
TOPIC_USBL,
|
||||
iter_mcap_messages,
|
||||
load_csv_nav,
|
||||
load_mcap,
|
||||
)
|
||||
|
||||
|
||||
def test_load_mcap_returns_dataframes(fake_mcap: Path) -> None:
|
||||
data = load_mcap(fake_mcap)
|
||||
assert set(data.keys()) == set(KNOWN_TOPICS)
|
||||
imu = data[TOPIC_IMU]
|
||||
usbl = data[TOPIC_USBL]
|
||||
bat = data[TOPIC_BATTERY]
|
||||
assert not imu.empty
|
||||
assert not usbl.empty
|
||||
assert not bat.empty
|
||||
# IMU ~50 Hz over 60s minus a 3s gap => ~2850 samples
|
||||
assert 2700 < len(imu) < 3000
|
||||
# USBL 2Hz over 60s => ~121 samples
|
||||
assert 115 < len(usbl) < 130
|
||||
# Battery 1Hz over 60s => 61 samples
|
||||
assert len(bat) == 61
|
||||
assert {"ts", "ax", "ay", "az", "gx", "gy", "gz"}.issubset(imu.columns)
|
||||
assert {"ts", "distance_m", "snr_db"}.issubset(usbl.columns)
|
||||
assert {"ts", "voltage_v"}.issubset(bat.columns)
|
||||
|
||||
|
||||
def test_load_mcap_sorted_by_ts(fake_mcap: Path) -> None:
|
||||
data = load_mcap(fake_mcap)
|
||||
for df in data.values():
|
||||
assert df["ts"].is_monotonic_increasing
|
||||
|
||||
|
||||
def test_iter_mcap_messages_filter(fake_mcap: Path) -> None:
|
||||
msgs = list(iter_mcap_messages(fake_mcap, topics=[TOPIC_BATTERY]))
|
||||
assert len(msgs) == 61
|
||||
assert all(t == TOPIC_BATTERY for t, _, _ in msgs)
|
||||
|
||||
|
||||
def test_load_csv_nav_missing_file(tmp_path: Path) -> None:
|
||||
df = load_csv_nav(tmp_path / "nope.csv")
|
||||
assert df.empty
|
||||
|
||||
|
||||
def test_load_csv_nav_parses(tmp_path: Path) -> None:
|
||||
p = tmp_path / "nav.csv"
|
||||
p.write_text("ts,lat,lon\n1.0,48.0,2.0\n2.0,48.1,2.1\n")
|
||||
df = load_csv_nav(p)
|
||||
assert len(df) == 2
|
||||
assert df["ts"].is_monotonic_increasing
|
||||
Reference in New Issue
Block a user