1

Compare la répartition des genres minifigs vs personnages

This commit is contained in:
2025-12-03 22:55:05 +01:00
parent e5dbf7bbaa
commit 996e4cb9ff
8 changed files with 142 additions and 7 deletions

View File

@@ -5,6 +5,7 @@ from pathlib import Path
from lib.rebrickable.minifig_characters import (
aggregate_by_character,
aggregate_by_gender,
aggregate_characters_by_gender,
aggregate_new_character_sets,
aggregate_new_characters_by_year,
aggregate_variations_and_totals,
@@ -12,6 +13,7 @@ from lib.rebrickable.minifig_characters import (
aggregate_presence_by_year,
load_sets_enriched,
write_character_counts,
write_character_gender_counts,
write_new_character_sets_csv,
write_new_character_sets_markdown,
write_new_characters_by_year,
@@ -143,6 +145,23 @@ def test_aggregate_by_gender_counts_unique_figs() -> None:
]
def test_aggregate_characters_by_gender_unique_characters() -> None:
"""Compter les personnages distincts par genre (ignorer unknown)."""
aggregates = aggregate_characters_by_gender(
[
{"known_character": "A", "gender": "male"},
{"known_character": "A", "gender": "male"},
{"known_character": "B", "gender": "female"},
{"known_character": "C", "gender": "unknown"},
]
)
assert aggregates == [
{"gender": "female", "character_count": "1"},
{"gender": "male", "character_count": "1"},
]
def test_aggregate_new_characters_by_year_limits_range(tmp_path: Path) -> None:
"""Compter les nouveaux personnages par année en respectant la plage."""
sets_path = tmp_path / "sets_enriched.csv"
@@ -268,6 +287,19 @@ def test_write_character_variations_totals_outputs_csv(tmp_path: Path) -> None:
assert destination.read_text() == "known_character,gender,variation_count,total_minifigs\nA,male,2,3\nB,female,1,1\n"
def test_write_character_gender_counts_outputs_csv(tmp_path: Path) -> None:
"""Écrit le CSV des comptes de personnages par genre."""
destination = tmp_path / "character_gender.csv"
rows = [
{"gender": "female", "character_count": "2"},
{"gender": "male", "character_count": "3"},
]
write_character_gender_counts(destination, rows)
assert destination.read_text() == "gender,character_count\nfemale,2\nmale,3\n"
def test_write_new_characters_by_year_outputs_csv(tmp_path: Path) -> None:
"""Écrit le CSV des nouveaux personnages par année."""
destination = tmp_path / "new_characters.csv"