Cette mise a jour complete ameliore significativement la qualite et la maintenabilite du projet. 1. Extension de la couverture de tests Couverture globale passee de 8% a 16% (+100%) - Ajout de 25 nouveaux tests (total: 67 tests, 100% passent) - Nouveaux fichiers de tests: * tests/unit/test_gitea.py (17 tests) * tests/unit/test_fiches_tickets.py (8 tests) Etat de la couverture par module: - utils/gitea.py: 100% - utils/widgets.py: 100% - utils/logger.py: 94% - app/fiches/utils/tickets/core.py: 77% - utils/graph_utils.py: 59% 2. Documentation d'architecture complete Creation de 3 nouveaux documents (30 Ko total): - docs/ARCHITECTURE.md (15 Ko) * Architecture complete du projet * Flux de donnees detailles * Indices de vulnerabilite (IHH, ISG, ICS, IVC) * Structure du graphe NetworkX - docs/MODULES.md (15 Ko) * Guide des 11 modules principaux * Exemples de code (15+ snippets) * Bonnes pratiques * Guide de depannage - docs/README.md (4 Ko) * Index de toute la documentation Contenu documente: - 5 modules applicatifs - 6 modules utilitaires - 4 indices de vulnerabilite avec formules et seuils - Conventions de code 3. Reorganisation de la documentation Structure finale optimisee: - Racine: README.md (mis a jour) + Instructions.md - docs/: 11 documents organises par categorie Fichiers deplaces vers docs/: - README_connexion.md -> docs/CONNEXION.md - GUIDE_LOGS.md -> docs/ - GUIDE_RUFF.md -> docs/ - RAPPORT_RUFF.md -> docs/ - RAPPORT_CORRECTIONS_AUTO.md -> docs/ - REFACTORING_REPORT.md -> docs/ - VERIFICATION_LOGS.md -> docs/ - TODO_IA_BATCH.md -> docs/ 4. Ajout de docstrings 52 fonctions documentees en style Google (100%) Documentation en francais avec Args, Returns, Raises 5. Corrections automatiques Ruff Application de 347 corrections automatiques: - Formatage du code (line-length: 120) - Organisation des imports - Simplifications syntaxiques - Suppressions de code mort - Ameliorations de performance 6. Configuration qualite du code Nouveaux fichiers: - pyproject.toml: configuration Ruff complete - .vscode/settings.json: integration Ruff avec formatOnSave - GUIDE_RUFF.md: documentation du linter - GUIDE_LOGS.md: documentation du logging - .gitignore: ajout htmlcov/ pour rapports de couverture Etat final du projet: - Linter: Ruff configure (15 regles actives) - Tests: 67 tests (100% passent) - Couverture de code: 16% - Docstrings: 52/52 (100%) - Documentation: 11 fichiers organises Impact: - Tests plus robustes et maintenables - Documentation technique complete - Meilleure organisation des fichiers - Workflow optimise avec Ruff - Code pret pour integration continue References: - Architecture: docs/ARCHITECTURE.md - Guide modules: docs/MODULES.md - Tests: tests/unit/ - Configuration: pyproject.toml Co-Authored-By: Claude <noreply@anthropic.com>
146 lines
3.4 KiB
Python
146 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 pytest
|
|
import sys
|
|
import tempfile
|
|
import networkx as nx
|
|
from pathlib import Path
|
|
|
|
# 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
|