SPB Git

spb/wp36_uqo

Public
2.1 KB · 45 lines python
1"""End-to-end pipeline test on the clearly labelled synthetic fixture."""2import json3import os4import shutil5from pathlib import Path67import pytest8910def test_pipeline_on_synthetic(tmp_path, monkeypatch):11    from ucml import synthetic12    db = synthetic.make(tmp_path / "synthetic" / "autoka-synthetic.db", n_listings=1500)13    monkeypatch.setenv("UCML_ROOT", str(tmp_path))14    monkeypatch.setenv("UCML_SNAPSHOT", str(db))15    import importlib16    from ucml import config17    importlib.reload(config)18    from ucml import ingest, cleaning19    importlib.reload(ingest); importlib.reload(cleaning)20    (tmp_path / "data" / "raw" / "registry").mkdir(parents=True)21    real_reg = Path(__file__).resolve().parents[1] / "data" / "raw" / "registry"22    srcs = {"_comment": "synthetic", "sources": [{"id": f"synthdealer{i:02d}", "name": f"D{i}", "type": "direct", "region": "Montréal"} for i in range(20)]23            + [{"id": "otogo", "name": "Otogo", "type": "portail"}]}24    (tmp_path / "data" / "raw" / "registry" / "sources.json").write_text(json.dumps(srcs))25    (tmp_path / "data" / "raw" / "registry" / "villes_gps.json").write_text(json.dumps({"ville": [45.5, -73.6]}))26    m = ingest.run(snapshot=db, outdir=tmp_path / "data" / "interim", with_hash=False)27    assert m["rows"]["vehicles"] == 150028    importlib.reload(config)29    stats = cleaning.run(interim=tmp_path / "data" / "interim", out=tmp_path / "data" / "processed", registry=tmp_path / "data" / "raw" / "registry")30    assert stats["S0"] == 150031    assert stats["S1_hedonic"] > 100032    assert (tmp_path / "data" / "processed" / "exclusions.csv").exists()33    assert (tmp_path / "data" / "processed" / "price_events.parquet").exists()343536def test_first_cut_never_null_in_risk_set():37    """Regression test for E-016: first_cut must be 0 (not NULL) for listing-days of never-cut listings."""38    import polars as pl39    from ucml import config as C40    p = C.PROCESSED / "risk_set.parquet"41    if not p.exists():42        pytest.skip("risk set not built")43    rs = pl.read_parquet(p, columns=["first_cut", "cut", "exit"])44    assert rs["first_cut"].null_count() == 0 and rs["cut"].null_count() == 0 and rs["exit"].null_count() == 045
Files · d0f6445591c09fe14b42fb37035f398825960706
Menu

Theme