"""End-to-end check on clean synthetic charts (the CI accuracy target).""" import numpy as np import pytest from plotscribe import export, pipeline from tests import synth from tests.metrics import AxisInfo, score_table SEEDS = range(9000, 9010) # two charts of each kind @pytest.fixture(scope="module") def charts(tmp_path_factory): out = tmp_path_factory.mktemp("synth") return synth.generate_set(len(SEEDS), out, "clean", SEEDS.start) def _score(path): import json gt = json.loads(path.with_suffix(".json").read_text()) res = pipeline.run(path) kind = "scatter" if gt["spec"]["kind"] == "scatter" else ("categorical" if gt["categories"] else "numeric") sc = score_table(res.table, synth.ground_truth_frame(gt), kind, AxisInfo(*sorted(gt["xlim"])), AxisInfo(*sorted(gt["ylim"]), log=gt["yscale"] == "log")) return res, sc, gt def test_clean_median_error_under_one_percent(charts): medians, recalls = [], [] for p in charts: res, sc, gt = _score(p) assert res.extra["status"] == "ok", (p.name, res.warnings) assert ("bar" in res.chart_type) == ("bar" in gt["spec"]["kind"]), p.name medians.append(sc.median) recalls.append(sc.recall) assert np.nanmedian(medians) < 0.01 assert np.mean(recalls) > 0.9 def test_outputs_written(charts, tmp_path): res = pipeline.run(charts[0]) paths = export.write_all(res, tmp_path, "c", debug=True) assert all(p.exists() for p in paths.values()) assert paths["csv"].read_text().strip()