32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
"""Tests des visualisations de rareté des pièces."""
|
|
|
|
import matplotlib
|
|
from pathlib import Path
|
|
from PIL import Image
|
|
|
|
from lib.plots.part_rarity import plot_part_rarity
|
|
|
|
|
|
matplotlib.use("Agg")
|
|
|
|
|
|
def test_plot_part_rarity_with_images(tmp_path: Path) -> None:
|
|
"""Génère le graphique des pièces rares avec incrustation des visuels."""
|
|
data_path = tmp_path / "part_rarity_exclusive.csv"
|
|
destination = tmp_path / "figures" / "step34" / "part_rarity.png"
|
|
resources_dir = tmp_path / "figures" / "rebrickable"
|
|
(resources_dir / "1000" / "rare_parts").mkdir(parents=True)
|
|
(resources_dir / "2000" / "rare_parts").mkdir(parents=True)
|
|
Image.new("RGB", (50, 50), color=(255, 0, 0)).save(resources_dir / "1000" / "rare_parts" / "p1.jpg")
|
|
Image.new("RGB", (50, 50), color=(0, 255, 0)).save(resources_dir / "2000" / "rare_parts" / "p2.jpg")
|
|
data_path.write_text(
|
|
"part_num,part_name,part_cat_id,part_category,sample_set_num,sample_set_id,filtered_quantity,filtered_set_count,other_sets_quantity,catalog_total_quantity,filtered_share\n"
|
|
"p1,Brick 1x1,1,Bricks,1000-1,1000,3,2,0,3,1.0000\n"
|
|
"p2,Plate 1x2,1,Bricks,2000-1,2000,2,1,1,3,0.6667\n"
|
|
)
|
|
|
|
plot_part_rarity(data_path, destination, resources_dir=resources_dir, show_images=True)
|
|
|
|
assert destination.exists()
|
|
assert destination.stat().st_size > 0
|