You've already forked etude_lego_jurassic_world
Aère le graphique des nouveaux personnages
This commit is contained in:
@@ -5,11 +5,13 @@ from pathlib import Path
|
||||
from lib.rebrickable.minifig_characters import (
|
||||
aggregate_by_character,
|
||||
aggregate_by_gender,
|
||||
aggregate_new_characters_by_year,
|
||||
aggregate_variations_and_totals,
|
||||
aggregate_character_spans,
|
||||
aggregate_presence_by_year,
|
||||
load_sets_enriched,
|
||||
write_character_counts,
|
||||
write_new_characters_by_year,
|
||||
write_character_variations_totals,
|
||||
write_gender_counts,
|
||||
)
|
||||
@@ -137,6 +139,39 @@ def test_aggregate_by_gender_counts_unique_figs() -> None:
|
||||
]
|
||||
|
||||
|
||||
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"
|
||||
sets_path.write_text(
|
||||
"set_num,year\n"
|
||||
"123-1,2015\n"
|
||||
"124-1,2016\n"
|
||||
"125-1,2017\n"
|
||||
"126-1,2014\n"
|
||||
)
|
||||
sets_years = load_sets_enriched(sets_path)
|
||||
minifigs_rows = [
|
||||
{"set_num": "123-1", "known_character": "Owen Grady", "fig_num": "fig-owen-1", "part_num": "head-a"},
|
||||
{"set_num": "124-1", "known_character": "Owen Grady", "fig_num": "fig-owen-2", "part_num": "head-b"},
|
||||
{"set_num": "125-1", "known_character": "Ellie Sattler", "fig_num": "fig-ellie-1", "part_num": "head-c"},
|
||||
{"set_num": "126-1", "known_character": "Alan Grant", "fig_num": "fig-grant-1", "part_num": "head-d"},
|
||||
]
|
||||
|
||||
counts = aggregate_new_characters_by_year(
|
||||
minifigs_rows,
|
||||
sets_years,
|
||||
excluded_characters=["Figurant"],
|
||||
start_year=2015,
|
||||
end_year=2017,
|
||||
)
|
||||
|
||||
assert counts == [
|
||||
{"year": "2015", "new_characters": "1"},
|
||||
{"year": "2016", "new_characters": "0"},
|
||||
{"year": "2017", "new_characters": "1"},
|
||||
]
|
||||
|
||||
|
||||
def test_write_character_counts_outputs_csv(tmp_path: Path) -> None:
|
||||
"""Écrit le CSV des comptes par personnage."""
|
||||
destination = tmp_path / "counts.csv"
|
||||
@@ -176,6 +211,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_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"
|
||||
rows = [
|
||||
{"year": "2015", "new_characters": "3"},
|
||||
{"year": "2016", "new_characters": "1"},
|
||||
]
|
||||
|
||||
write_new_characters_by_year(destination, rows)
|
||||
|
||||
assert destination.read_text() == "year,new_characters\n2015,3\n2016,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"
|
||||
|
||||
Reference in New Issue
Block a user