You've already forked etude_lego_jurassic_world
Ajoute l’étape 25 de répartition des minifigs par genre
This commit is contained in:
@@ -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"
|
||||
|
||||
26
tests/test_minifig_gender_share_plot.py
Normal file
26
tests/test_minifig_gender_share_plot.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""Tests du diagramme de répartition des genres."""
|
||||
|
||||
import matplotlib
|
||||
from pathlib import Path
|
||||
|
||||
from lib.plots.minifig_gender_share import plot_minifig_gender_share
|
||||
|
||||
|
||||
matplotlib.use("Agg")
|
||||
|
||||
|
||||
def test_plot_minifig_gender_share(tmp_path: Path) -> None:
|
||||
"""Génère le graphique de répartition par genre."""
|
||||
counts_path = tmp_path / "gender_counts.csv"
|
||||
destination = tmp_path / "figures" / "step25" / "minifig_gender_share.png"
|
||||
counts_path.write_text(
|
||||
"gender,minifig_count\n"
|
||||
"male,2\n"
|
||||
"female,1\n"
|
||||
"unknown,1\n"
|
||||
)
|
||||
|
||||
plot_minifig_gender_share(counts_path, destination)
|
||||
|
||||
assert destination.exists()
|
||||
assert destination.stat().st_size > 0
|
||||
Reference in New Issue
Block a user