protostar-climate-2026 / code /test_leakage.py
Tonic's picture
Protostar Climate submission: v2 forecast + v3/DCPP amendment audit (29 gated candidates)
49f3de8 verified
Raw History Blame Contribute Delete
1.36 kB
"""Leakage tests (run: .venv/Scripts/python.exe -m pytest code/test_leakage.py -q
or directly: .venv/Scripts/python.exe code/test_leakage.py)."""
from __future__ import annotations
import sys
from pathlib import Path
import pandas as pd
sys.path.insert(0, str(Path(__file__).parent))
from leakage import assert_dates_le_cutoff, assert_no_forbidden_artifacts
CODE_DIR = Path(__file__).parent
def test_cutoff_passes_pre2019():
assert_dates_le_cutoff(["2018-12-31", "1900-01-01"], "test")
def test_cutoff_rejects_2019():
try:
assert_dates_le_cutoff(["2019-01-01"], "test")
except ValueError:
return
raise AssertionError("2019 date was not rejected")
def test_no_forbidden_artifacts_in_forecast_code():
scanned = assert_no_forbidden_artifacts(CODE_DIR)
assert scanned, "no files scanned"
def test_manifest_dates_le_cutoff():
manifest = CODE_DIR.parent / "data" / "eo" / "manifest.csv"
if not manifest.exists():
return # EO fetch not run yet
df = pd.read_csv(manifest)
assert_dates_le_cutoff(df["datetime"], "EO manifest")
if __name__ == "__main__":
test_cutoff_passes_pre2019()
test_cutoff_rejects_2019()
test_no_forbidden_artifacts_in_forecast_code()
test_manifest_dates_le_cutoff()
print("all leakage tests passed")