Code/tests/conftest.py
Stéphan Peccini 8e2556c2b0
test(unit): +381 tests unitaires — couverture 16%→35%
- 9 nouveaux fichiers de tests (persistance, translations, fiches, indices, IHH)
- Enrichissement des tests existants (graph_utils, gitea, widgets, tickets)
- 67→448 tests, tous passent

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 11:52:21 +01:00

143 lines
3.4 KiB
Python

"""Configuration pytest et fixtures globales pour les tests FabNum.
Ce fichier contient les fixtures partagées entre tous les tests.
"""
import sys
from pathlib import Path
import networkx as nx
import pytest
# Ajouter le répertoire racine au PYTHONPATH pour les imports
ROOT_DIR = Path(__file__).parent.parent
sys.path.insert(0, str(ROOT_DIR))
@pytest.fixture(scope="session")
def test_data_dir():
"""Chemin vers le dossier des données de test."""
return Path(__file__).parent / "fixtures"
@pytest.fixture(scope="session")
def sample_dot_file(test_data_dir):
"""Chemin vers le fichier DOT de test."""
return test_data_dir / "sample_graph.dot"
@pytest.fixture
def temp_log_dir(tmp_path):
"""Crée un répertoire temporaire pour les logs de test."""
log_dir = tmp_path / "logs"
log_dir.mkdir()
return log_dir
@pytest.fixture
def simple_graph():
"""Crée un graphe NetworkX simple pour les tests.
Structure:
ProduitA (niveau 0) → ComposantB (niveau 1) → MineraiC (niveau 2)
"""
G = nx.DiGraph()
# Produit final
G.add_node("ProduitA", niveau=0, label="Produit A")
# Composant
G.add_node("ComposantB", niveau=1, label="Composant B")
# Minerai
G.add_node("MineraiC", niveau=2, label="Minerai C", ivc=25)
# Opération
G.add_node("Fabrication_ComposantB", niveau=10, ihh_pays=30, ihh_acteurs=20)
# Pays d'opération
G.add_node("Chine_Fabrication_ComposantB", niveau=11)
# Pays géographique
G.add_node("Chine_geographique", niveau=99, isg=54, label="Chine")
# Arêtes
G.add_edge("ProduitA", "ComposantB")
G.add_edge("ComposantB", "MineraiC", ics=0.5)
G.add_edge("ComposantB", "Fabrication_ComposantB")
G.add_edge("Fabrication_ComposantB", "Chine_Fabrication_ComposantB")
G.add_edge("Chine_Fabrication_ComposantB", "Chine_geographique")
return G
@pytest.fixture
def complex_graph():
"""Crée un graphe plus complexe avec multiples chemins.
Structure:
ProduitX → ComposantY → MineraiZ1
→ MineraiZ2
ProduitX → ComposantW → MineraiZ1
"""
G = nx.DiGraph()
# Produit final
G.add_node("ProduitX", niveau=0, label="Produit X")
# Composants
G.add_node("ComposantY", niveau=1, label="Composant Y")
G.add_node("ComposantW", niveau=1, label="Composant W")
# Minerais
G.add_node("MineraiZ1", niveau=2, label="Minerai Z1", ivc=60)
G.add_node("MineraiZ2", niveau=2, label="Minerai Z2", ivc=15)
# Opérations
G.add_node("Extraction_MineraiZ1", niveau=10, ihh_pays=70)
G.add_node("Reserves_MineraiZ1", niveau=10, ihh_pays=80)
# Arêtes
G.add_edge("ProduitX", "ComposantY")
G.add_edge("ProduitX", "ComposantW")
G.add_edge("ComposantY", "MineraiZ1", ics=0.8)
G.add_edge("ComposantY", "MineraiZ2", ics=0.3)
G.add_edge("ComposantW", "MineraiZ1", ics=0.6)
return G
@pytest.fixture
def sample_config_yaml(tmp_path):
"""Crée un fichier config.yaml temporaire pour les tests."""
config_content = """
seuils:
ISG:
vert:
max: 40
orange:
min: 40
max: 70
rouge:
min: 70
IHH:
vert:
max: 15
orange:
min: 15
max: 25
rouge:
min: 25
IVC:
vert:
max: 15
orange:
min: 15
max: 60
rouge:
min: 60
"""
config_file = tmp_path / "config.yaml"
config_file.write_text(config_content)
return config_file