1

Ajoute l’étape 25 de répartition des minifigs par genre

This commit is contained in:
2025-12-02 11:42:50 +01:00
parent f5c1fa6333
commit 1f18195df2
9 changed files with 190 additions and 26 deletions

View File

@@ -4,10 +4,12 @@ from pathlib import Path
from lib.rebrickable.minifig_characters import (
aggregate_by_character,
aggregate_by_gender,
aggregate_character_spans,
aggregate_presence_by_year,
load_sets_enriched,
write_character_counts,
write_gender_counts,
)
@@ -66,6 +68,24 @@ def test_aggregate_by_character_counts_unique_figs() -> None:
]
def test_aggregate_by_gender_counts_unique_figs() -> None:
"""Compter les minifigs distinctes par genre."""
aggregates = aggregate_by_gender(
[
{"fig_num": "fig-a", "gender": "male"},
{"fig_num": "fig-a", "gender": "male"},
{"fig_num": "fig-b", "gender": "female"},
{"fig_num": "fig-c", "gender": ""},
]
)
assert aggregates == [
{"gender": "female", "minifig_count": "1"},
{"gender": "male", "minifig_count": "1"},
{"gender": "unknown", "minifig_count": "1"},
]
def test_write_character_counts_outputs_csv(tmp_path: Path) -> None:
"""Écrit le CSV des comptes par personnage."""
destination = tmp_path / "counts.csv"
@@ -79,6 +99,19 @@ def test_write_character_counts_outputs_csv(tmp_path: Path) -> None:
assert destination.read_text() == "known_character,gender,minifig_count\nA,male,2\nB,female,1\n"
def test_write_gender_counts_outputs_csv(tmp_path: Path) -> None:
"""Écrit le CSV des comptes par genre."""
destination = tmp_path / "gender_counts.csv"
rows = [
{"gender": "male", "minifig_count": "2"},
{"gender": "female", "minifig_count": "1"},
]
write_gender_counts(destination, rows)
assert destination.read_text() == "gender,minifig_count\nmale,2\nfemale,1\n"
def test_aggregate_presence_by_year_excludes_figurants(tmp_path: Path) -> None:
"""Calcule le total annuel en excluant les figurants."""
sets_path = tmp_path / "sets_enriched.csv"