shortstats/tests/non_regression/test_references_specs.py
ploush 81ef12a9cd
Some checks failed
build / test (push) Failing after 2m48s
build / images (collector) (push) Has been skipped
build / images (web) (push) Has been skipped
upgrade 1.4.0
2026-11-29 20:43:50 +01:00

85 lines
3.8 KiB
Python

"""Specs Vega-Lite figées, sans base : chaque combinaison de données, de type et de couleur,
plusieurs ordonnées et un type par catégorie. Toute différence de résultat (spec,
explication, commandes) est signalée cas par cas (voir tests/outils/references.py)."""
from __future__ import annotations
import pytest
from shortstats.web import chart_catalog, chart_config, chart_view, charts, highlight, marks
from ..outils.lignes import ALL_X, ALL_Y, fake_rows, multi_rows
from ..outils.references import verifier
SPEC_X = ["publish_date", "views", "weekday", "theme", "publish_hour", "title", "channel"]
THEME_YS = ["theme_rate@56", "theme_rate@6"]
TYPES = ("auto", "scatter", "line", "bar", "boxplot", "histogram", "heatmap")
def _build(raw: dict, rows=None, order=None, view=None) -> dict | str:
try:
cfg = chart_config.validate_config(raw)
except chart_catalog.ChartError as exc:
return f"refusé : {exc}"
return charts.build(cfg, rows(cfg) if rows else fake_rows(cfg), order, view)
def test_reference_j7_une_ordonnee():
out = {}
for x in ALL_X:
for y in ALL_Y:
for ctype in TYPES:
for color in (None, "channel", "views"):
for scale in ("auto", "log"):
raw = {"x": x, "y": y, "type": ctype, "color": color, "scale": scale}
out[f"{x}|{y}|{ctype}|{color}|{scale}"] = _build(raw)
assert len(out) > 2000
verifier("specs_j7", out)
def test_reference_j7_plusieurs_ordonnees():
out = {}
for x in SPEC_X:
ys_list = ((["views@6", "views@8"], ["views@6", "views@8", "likes@6"], ["views", "duration"])
if x != "theme" else (THEME_YS, THEME_YS + ["theme_comments@56"]))
for ys in ys_list:
for t in ("auto", "scatter", "line", "bar"):
for t2 in ("", "line", "bar", "scatter"):
for ind in (False, True):
for split in (False, True):
raw = {"x": x, "y": ys[0], "y_more": ys[1:], "type": t, "type2": t2, "split_channels": split}
out[f"{x}|{'+'.join(ys)}|{t}|{t2}|{ind}|{split}"] = _build(
raw, multi_rows, ["Chaîne A", "Chaîne B"], chart_view.View(individual=ind))
assert len(out) > 500
verifier("specs_j7_multi", out)
@pytest.mark.parametrize("style", [{}, {"shape": "square", "point": "large", "line": "thick"}])
def test_reference_styles_et_agregations(style):
"""Style des points et courbes, agrégations par ordonnée et limites (N dernières vidéos)."""
out = {}
aggs_list = ([{"op": "median"}], [{"op": "mean", "limit": {"last": 5}}],
[{"op": "max"}, {"op": "sum", "limit": {"last": 3}}])
for x in ("publish_date", "weekday", "publish_hour", "duration"):
for aggs in aggs_list:
ys = ["views", "likes"][: len(aggs)]
raw = {"x": x, "y": ys[0], "y_more": ys[1:], "aggs": aggs, "type": "auto", "split_channels": False}
try:
cfg = chart_config.validate_config(raw)
except chart_catalog.ChartError as exc:
out[f"{x}|{aggs}"] = f"refusé : {exc}"
continue
rows = multi_rows(cfg) if ys[1:] else fake_rows(cfg)
published = {r[0]: "2026-06-01T12:00:00" for r in rows}
res = charts.build(cfg, rows, ["Chaîne A", "Chaîne B"], None, published)
marks.apply(res, style)
out[f"{x}|{aggs}"] = res
verifier(f"specs_styles_{'defaut' if not style else 'perso'}", out)
def test_reference_formes_des_mises_en_avant():
"""Formes, traits et tailles proposés pour les vidéos mises en avant."""
verifier("mises_en_avant_catalogue", {
"formes": highlight.SHAPES, "rangs": highlight.RANKS,
"max": highlight.MAX, "rang_max": highlight.MAX_RANK,
})