You've already forked etude_lego_jurassic_world
Ajoute le graphique des personnages représentés
This commit is contained in:
37
tests/test_minifig_characters.py
Normal file
37
tests/test_minifig_characters.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""Tests de l'agrégation des minifigs par personnage."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from lib.rebrickable.minifig_characters import aggregate_by_character, write_character_counts
|
||||
|
||||
|
||||
def test_aggregate_by_character_counts_unique_figs() -> None:
|
||||
"""Compter les minifigs distinctes par personnage en excluant les noms vides."""
|
||||
aggregates = aggregate_by_character(
|
||||
[
|
||||
{"set_num": "123-1", "part_num": "head-a", "known_character": "Owen Grady", "fig_num": "fig-owen-1"},
|
||||
{"set_num": "124-1", "part_num": "head-b", "known_character": "Owen Grady", "fig_num": "fig-owen-1"},
|
||||
{"set_num": "125-1", "part_num": "head-c", "known_character": "Owen Grady", "fig_num": "fig-owen-2"},
|
||||
{"set_num": "126-1", "part_num": "head-d", "known_character": "Figurant", "fig_num": "fig-guard-1"},
|
||||
{"set_num": "128-1", "part_num": "head-f", "known_character": "Figurant", "fig_num": "fig-guard-1"},
|
||||
{"set_num": "129-1", "part_num": "head-g", "known_character": "", "fig_num": "fig-guard-2"},
|
||||
]
|
||||
)
|
||||
|
||||
assert aggregates == [
|
||||
{"known_character": "Owen Grady", "minifig_count": 2},
|
||||
{"known_character": "Figurant", "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"
|
||||
rows = [
|
||||
{"known_character": "A", "minifig_count": 2},
|
||||
{"known_character": "B", "minifig_count": 1},
|
||||
]
|
||||
|
||||
write_character_counts(destination, rows)
|
||||
|
||||
assert destination.read_text() == "known_character,minifig_count\nA,2\nB,1\n"
|
||||
25
tests/test_minifig_characters_plot.py
Normal file
25
tests/test_minifig_characters_plot.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""Tests du graphique minifigs par personnage."""
|
||||
|
||||
import matplotlib
|
||||
from pathlib import Path
|
||||
|
||||
from lib.plots.minifig_characters import plot_minifigs_per_character
|
||||
|
||||
|
||||
matplotlib.use("Agg")
|
||||
|
||||
|
||||
def test_plot_minifigs_per_character(tmp_path: Path) -> None:
|
||||
"""Génère l'image de comptage par personnage."""
|
||||
counts_path = tmp_path / "counts.csv"
|
||||
destination = tmp_path / "figures" / "step22" / "minifig_characters.png"
|
||||
counts_path.write_text(
|
||||
"known_character,minifig_count\n"
|
||||
"Owen Grady,2\n"
|
||||
"Figurant,1\n"
|
||||
)
|
||||
|
||||
plot_minifigs_per_character(counts_path, destination)
|
||||
|
||||
assert destination.exists()
|
||||
assert destination.stat().st_size > 0
|
||||
Reference in New Issue
Block a user