Spaces:
Runtime error
Runtime error
File size: 1,557 Bytes
6f423bd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | """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()
|