You've already forked etude_lego_jurassic_world
Ajoute l’étape 26 pièces/minifigs
This commit is contained in:
70
tests/test_minifig_parts_correlation.py
Normal file
70
tests/test_minifig_parts_correlation.py
Normal file
@@ -0,0 +1,70 @@
|
||||
"""Tests de la préparation de corrélation pièces/minifigs."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from lib.rebrickable.minifig_parts_correlation import build_correlation_rows
|
||||
|
||||
|
||||
def write_csv(path: Path, content: str) -> None:
|
||||
"""Écrit un CSV brut."""
|
||||
path.write_text(content)
|
||||
|
||||
|
||||
def test_build_correlation_rows_merges_filtered_and_catalog(tmp_path: Path) -> None:
|
||||
"""Construit les lignes de corrélation pour filtrés et catalogue global."""
|
||||
filtered_counts_path = tmp_path / "minifig_counts_by_set.csv"
|
||||
write_csv(
|
||||
filtered_counts_path,
|
||||
"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",
|
||||
)
|
||||
filtered_sets_path = tmp_path / "sets_enriched.csv"
|
||||
write_csv(
|
||||
filtered_sets_path,
|
||||
"set_num,num_parts\n"
|
||||
"123-1,300\n"
|
||||
"124-1,150\n",
|
||||
)
|
||||
all_sets_path = tmp_path / "sets.csv"
|
||||
write_csv(
|
||||
all_sets_path,
|
||||
"set_num,name,year,theme_id,num_parts\n"
|
||||
"123-1,Set A,2020,1,300\n"
|
||||
"124-1,Set B,2021,1,150\n"
|
||||
"200-1,Set C,2019,1,100\n",
|
||||
)
|
||||
inventories_path = tmp_path / "inventories.csv"
|
||||
write_csv(
|
||||
inventories_path,
|
||||
"id,version,set_num\n"
|
||||
"10,1,123-1\n"
|
||||
"20,2,123-1\n"
|
||||
"30,1,124-1\n"
|
||||
"40,1,200-1\n",
|
||||
)
|
||||
inventory_minifigs_path = tmp_path / "inventory_minifigs.csv"
|
||||
write_csv(
|
||||
inventory_minifigs_path,
|
||||
"inventory_id,fig_num,quantity\n"
|
||||
"10,fig-a,1\n"
|
||||
"20,fig-a,2\n"
|
||||
"30,fig-b,1\n"
|
||||
"40,fig-c,3\n",
|
||||
)
|
||||
|
||||
rows = build_correlation_rows(
|
||||
filtered_counts_path,
|
||||
filtered_sets_path,
|
||||
all_sets_path,
|
||||
inventories_path,
|
||||
inventory_minifigs_path,
|
||||
)
|
||||
|
||||
assert rows == [
|
||||
{"scope": "filtered", "set_num": "123-1", "num_parts": "300", "minifig_count": "2"},
|
||||
{"scope": "filtered", "set_num": "124-1", "num_parts": "150", "minifig_count": "1"},
|
||||
{"scope": "catalog", "set_num": "123-1", "num_parts": "300", "minifig_count": "2"},
|
||||
{"scope": "catalog", "set_num": "124-1", "num_parts": "150", "minifig_count": "1"},
|
||||
{"scope": "catalog", "set_num": "200-1", "num_parts": "100", "minifig_count": "3"},
|
||||
]
|
||||
28
tests/test_minifig_parts_correlation_plot.py
Normal file
28
tests/test_minifig_parts_correlation_plot.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""Tests du graphique de corrélation pièces/minifigs."""
|
||||
|
||||
import matplotlib
|
||||
from pathlib import Path
|
||||
|
||||
from lib.plots.minifig_parts_correlation import plot_minifig_parts_correlation
|
||||
|
||||
|
||||
matplotlib.use("Agg")
|
||||
|
||||
|
||||
def test_plot_minifig_parts_correlation(tmp_path: Path) -> None:
|
||||
"""Génère le graphique comparatif pièces/minifigs."""
|
||||
correlation_path = tmp_path / "minifig_parts_correlation.csv"
|
||||
destination = tmp_path / "figures" / "step26" / "minifig_parts_correlation.png"
|
||||
correlation_path.write_text(
|
||||
"scope,set_num,num_parts,minifig_count\n"
|
||||
"filtered,123-1,300,2\n"
|
||||
"filtered,124-1,150,1\n"
|
||||
"catalog,123-1,300,2\n"
|
||||
"catalog,124-1,150,1\n"
|
||||
"catalog,200-1,100,3\n"
|
||||
)
|
||||
|
||||
plot_minifig_parts_correlation(correlation_path, destination)
|
||||
|
||||
assert destination.exists()
|
||||
assert destination.stat().st_size > 0
|
||||
Reference in New Issue
Block a user