fix(tests): improve rollup correctness assertions in test_dashboard_stats.py

Refactor the rollup correctness test to enhance the accuracy of assertions. The test now calculates expected values for snr_count, rssi_count, and snr_sum based on a specific date range, ensuring that the results align with the database's message_stats. This change improves the reliability of the test by accounting for potential discrepancies in timestamp handling.
This commit is contained in:
agessaman
2026-08-06 21:03:22 -07:00
parent 34bfe807f7
commit ea8b3491de
+18 -5
View File
@@ -428,12 +428,25 @@ class TestRollupCorrectness:
"""Means cannot be re-aggregated across a window; sums and counts can."""
seed_database(viewer.db_path)
_refresh(viewer)
row = _rollup(viewer, local_date_str())
assert row["snr_count"] == MESSAGES
assert row["rssi_count"] == MESSAGES
today = local_date_str()
row = _rollup(viewer, today)
# Seed timestamps are `now - i`, so near midnight some rows land on
# yesterday. Compare against the same day window the rollup uses.
start, end = day_bounds(today)
with sqlite3.connect(viewer.db_path) as conn:
expected = conn.execute("SELECT SUM(snr) FROM message_stats").fetchone()[0]
assert row["snr_sum"] == pytest.approx(expected)
expected = conn.execute(
"""
SELECT SUM(snr),
SUM(CASE WHEN snr IS NOT NULL THEN 1 ELSE 0 END),
SUM(CASE WHEN rssi IS NOT NULL THEN 1 ELSE 0 END)
FROM message_stats
WHERE timestamp >= ? AND timestamp < ?
""",
(start, end),
).fetchone()
assert row["snr_count"] == expected[1]
assert row["rssi_count"] == expected[2]
assert row["snr_sum"] == pytest.approx(expected[0])
def test_missing_stats_tables_degrade_to_null(self, viewer):
"""`collect_stats = false` leaves the tables absent entirely."""