"""Tests du diagramme de longévité des personnages."""

import matplotlib
from pathlib import Path

from lib.plots.minifig_character_spans import plot_character_spans


matplotlib.use("Agg")


def test_plot_character_spans(tmp_path: Path) -> None:
    """Génère le graphique de span des personnages."""
    spans_path = tmp_path / "minifig_character_spans.csv"
    destination = tmp_path / "figures" / "step24" / "minifig_character_spans.png"
    spans_path.write_text(
        "known_character,start_year,end_year,total_minifigs,gender\n"
        "Owen Grady,2020,2022,3,male\n"
        "Figurant,2019,2020,2,unknown\n"
    )

    plot_character_spans(spans_path, destination)

    assert destination.exists()
    assert destination.stat().st_size > 0
