parking-land/test_present.py
2025-03-16 12:54:21 +01:00

74 lines
No EOL
2.4 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Script de test pour vérifier le bon fonctionnement de la génération de rapport HTML
à partir des données JSON de décompte urbain.
"""
import os
import json
import datetime
from present import generate_html_from_json
def create_test_data():
"""Crée un fichier JSON de test avec des données fictives."""
test_data = {
"city_name": "Ville Test",
"longueur_route_km": 228.33,
"road_cycleway_km": 12.5,
"compte_highways": 3530,
"surface_route_km2": 1.59,
"building_count": 2516,
"building_area": 2.65,
"building_sizes": [0, 10, 50, 100, 200, 500, float('inf')],
"building_size_counts": [120, 450, 780, 650, 400, 116],
"compte_piste_cyclable": 42,
"car_parking_capacity_provided": 491,
"roundabout_count": 12,
"mini_roundabout_count": 5,
"surface_parking_km2": 0.35,
"surface_bicycle_parking_km2": 0.042,
"parking_with_capacity_count": 43,
"capacity_bicycle_parking_provided": 125,
"bicycle_parking_surface_from_capacity_provided_in_m2": 250,
"charging_stations": 14,
"charging_stations_with_capacity_count": 12,
"charging_stations_capacity_provided": 28,
"charging_points": 32,
"date_generation": datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S")
}
with open('test_data.json', 'w', encoding='utf-8') as f:
json.dump(test_data, f, indent=2, ensure_ascii=False)
return 'test_data.json'
def test_template(template_file):
"""Teste la génération HTML avec un template spécifique."""
test_json = create_test_data()
output_html = f"resultat_{os.path.splitext(template_file)[0]}.html"
success = generate_html_from_json(test_json, output_html, template_file)
if success:
print(f"✅ Test réussi avec {template_file} ! Fichier généré : {output_html}")
else:
print(f"❌ Échec du test avec {template_file}")
return success
def main():
"""Fonction principale qui exécute les tests."""
print("🧪 Démarrage des tests de génération de rapports HTML...")
# Test avec le template original
test_template('template.html')
# Test avec le template amélioré
test_template('template_ameliore.html.j2')
print("🏁 Tests terminés.")
if __name__ == "__main__":
main()