47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
"""Tests de l'extraction des têtes de minifigs par set."""
|
|
|
|
from pathlib import Path
|
|
|
|
from lib.rebrickable.minifigs_by_set import build_minifigs_by_set
|
|
|
|
|
|
def write_csv(path: Path, content: str) -> None:
|
|
"""Écrit un CSV brut."""
|
|
path.write_text(content)
|
|
|
|
|
|
def test_build_minifigs_by_set_filters_spares_and_deduplicates(tmp_path) -> None:
|
|
"""Identifie les têtes de minifigs par set en dédupliquant et en excluant les rechanges."""
|
|
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-b,ffffff,false,123-1,123,2020,2,false,true\n"
|
|
"head-b,ffffff,false,123-1,123,2020,1,true,true\n"
|
|
"head-b,ffffff,false,124-1,124,2021,1,false,true\n"
|
|
"other,000000,false,123-1,123,2020,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",
|
|
)
|
|
destination_path = tmp_path / "minifigs_by_set.csv"
|
|
|
|
build_minifigs_by_set(
|
|
parts_filtered_path,
|
|
parts_catalog_path,
|
|
destination_path,
|
|
)
|
|
|
|
assert destination_path.read_text() == (
|
|
"set_num,part_num,part_name\n"
|
|
"123-1,head-a,Head A\n"
|
|
"123-1,head-b,Head B\n"
|
|
"124-1,head-b,Head B\n"
|
|
)
|