You've already forked etude_lego_jurassic_world
Ajoute le graphique du nombre de minifigs par set
This commit is contained in:
47
tests/test_minifig_counts.py
Normal file
47
tests/test_minifig_counts.py
Normal file
@@ -0,0 +1,47 @@
|
||||
"""Tests du comptage de minifigs par set."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from lib.rebrickable.minifig_counts import build_minifig_counts_by_set
|
||||
|
||||
|
||||
def write_csv(path: Path, content: str) -> None:
|
||||
"""Écrit un CSV brut."""
|
||||
path.write_text(content)
|
||||
|
||||
|
||||
def test_build_minifig_counts_by_set_counts_heads_without_spares(tmp_path: Path) -> None:
|
||||
"""Compte les têtes hors rechanges pour chaque set et conserve les sets à 0."""
|
||||
sets_path = tmp_path / "sets_enriched.csv"
|
||||
write_csv(
|
||||
sets_path,
|
||||
"set_num,name,year,set_id\n"
|
||||
"123-1,Set A,2020,123\n"
|
||||
"124-1,Set B,2021,124\n"
|
||||
"125-1,Set C,2022,125\n",
|
||||
)
|
||||
parts_filtered_path = tmp_path / "parts_filtered.csv"
|
||||
write_csv(
|
||||
parts_filtered_path,
|
||||
"part_num,color_rgb,is_translucent,set_num,set_id,year,quantity_in_set,is_spare,is_minifig_part\n"
|
||||
"head-a,ffffff,false,123-1,123,2020,1,false,true\n"
|
||||
"head-a,ffffff,false,123-1,123,2020,2,true,true\n"
|
||||
"head-b,ffffff,false,124-1,124,2021,3,false,true\n"
|
||||
"other,000000,false,124-1,124,2021,1,false,false\n",
|
||||
)
|
||||
parts_catalog_path = tmp_path / "parts.csv"
|
||||
write_csv(
|
||||
parts_catalog_path,
|
||||
"part_num,name,part_cat_id\n"
|
||||
"head-a,Head A,59\n"
|
||||
"head-b,Head B,59\n"
|
||||
"other,Other,1\n",
|
||||
)
|
||||
|
||||
counts = build_minifig_counts_by_set(sets_path, parts_filtered_path, parts_catalog_path)
|
||||
|
||||
assert counts == [
|
||||
{"set_num": "124-1", "set_id": "124", "name": "Set B", "year": "2021", "minifig_count": 3},
|
||||
{"set_num": "123-1", "set_id": "123", "name": "Set A", "year": "2020", "minifig_count": 1},
|
||||
{"set_num": "125-1", "set_id": "125", "name": "Set C", "year": "2022", "minifig_count": 0},
|
||||
]
|
||||
25
tests/test_minifig_counts_plot.py
Normal file
25
tests/test_minifig_counts_plot.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""Tests du graphique des minifigs par set."""
|
||||
|
||||
import matplotlib
|
||||
from pathlib import Path
|
||||
|
||||
from lib.plots.minifig_counts import plot_minifigs_per_set
|
||||
|
||||
|
||||
matplotlib.use("Agg")
|
||||
|
||||
|
||||
def test_plot_minifigs_per_set_outputs_image(tmp_path: Path) -> None:
|
||||
"""Génère l'image du nombre de minifigs par set."""
|
||||
counts_path = tmp_path / "minifig_counts_by_set.csv"
|
||||
destination_path = tmp_path / "figures" / "step20" / "minifigs_per_set.png"
|
||||
counts_path.write_text(
|
||||
"set_num,set_id,name,year,minifig_count\n"
|
||||
"123-1,123,Set A,2020,2\n"
|
||||
"124-1,124,Set B,2021,1\n"
|
||||
)
|
||||
|
||||
plot_minifigs_per_set(counts_path, destination_path)
|
||||
|
||||
assert destination_path.exists()
|
||||
assert destination_path.stat().st_size > 0
|
||||
Reference in New Issue
Block a user