128 lines
4.6 KiB
Python
128 lines
4.6 KiB
Python
import os
|
|
import json
|
|
import pandas as pd
|
|
import matplotlib.pyplot as plt
|
|
|
|
# Fichiers Allure
|
|
ALLURE_DIR = "ci-reports/allure-report"
|
|
|
|
print("📂 Contenu du dossier allure-report:", os.listdir(ALLURE_DIR))
|
|
print("📂 Contenu de widgets:", os.listdir(os.path.join(ALLURE_DIR, "widgets")))
|
|
print("📂 Contenu de data:", os.listdir(os.path.join(ALLURE_DIR, "data")))
|
|
|
|
DATA_DIR = os.path.join(ALLURE_DIR, "data")
|
|
WIDGETS_DIR = os.path.join(ALLURE_DIR, "widgets")
|
|
|
|
SUITES_CSV = os.path.join(DATA_DIR, "suites.csv")
|
|
SUITES_JSON = os.path.join(DATA_DIR, "suites.json")
|
|
SUMMARY_JSON = os.path.join(WIDGETS_DIR, "summary.json")
|
|
|
|
# ------------------- Graph Donut -------------------
|
|
import matplotlib.pyplot as plt
|
|
|
|
def generate_donut_chart(summary):
|
|
statuses = ['passed', 'failed', 'skipped', 'broken']
|
|
labels = ['Passed', 'Failed', 'Skipped', 'Broken']
|
|
colors = ['#4CAF50', '#F44336', '#FF9800', '#9C27B0']
|
|
values = [summary['statistic'].get(s, 0) for s in statuses]
|
|
|
|
time_info = summary.get("time", {})
|
|
duration = time_info.get("duration", "N/A")
|
|
min_duration = time_info.get("minDuration", "N/A")
|
|
max_duration = time_info.get("maxDuration", "N/A")
|
|
sum_duration = time_info.get("sumDuration", "N/A")
|
|
|
|
# Création du graphe
|
|
fig, ax = plt.subplots(figsize=(8, 5))
|
|
wedges, _ = ax.pie(values, labels=None, colors=colors, startangle=90,
|
|
wedgeprops=dict(width=0.4))
|
|
|
|
ax.legend(wedges, labels, loc="center left", bbox_to_anchor=(1, 0.5))
|
|
ax.set(aspect="equal", title="Résultat des tests")
|
|
|
|
# Ajouter un encadré texte avec les durées
|
|
text = (
|
|
f"**Total duration :** {duration} ms\n"
|
|
f"Min: {min_duration} ms Max: {max_duration} ms\n"
|
|
)
|
|
|
|
plt.text(-2.2, -1.2, text, fontsize=10, ha='left', va='top', family='monospace')
|
|
|
|
plt.savefig("summary.png", bbox_inches="tight")
|
|
plt.close()
|
|
|
|
|
|
# ------------------- Markdown -------------------
|
|
def generate_detailed_test_report(data, output_file="static-report.md"):
|
|
"""
|
|
Génère un rapport Markdown détaillé et l'écrit directement dans un fichier.
|
|
Structure:
|
|
- Nom du Test (en titre)
|
|
- Section Détails (dépliable)
|
|
- Informations complètes sous forme de tableau
|
|
|
|
Args:
|
|
data: Liste de dictionnaires contenant les données des tests
|
|
output_file: Chemin du fichier de sortie (par défaut: static-report.md)
|
|
"""
|
|
with open(output_file, "w") as f:
|
|
if not data:
|
|
f.write("# ⚠️ Aucun résultat de test disponible\n")
|
|
return
|
|
|
|
f.write("# 📊 Rapport Détaillé des Tests\n\n")
|
|
|
|
for test in data:
|
|
# Nom du test (titre principal)
|
|
test_name = test.get("Test Method", "Test sans nom")
|
|
f.write(f"## 🧪 {test_name}\n")
|
|
|
|
# Section Détails (dépliable)
|
|
f.write("<details>\n<summary>📌 <strong>Détails du test</strong></summary>\n\n")
|
|
|
|
# Tableau d'informations complètes
|
|
f.write("| Catégorie | Valeur |\n")
|
|
f.write("|-----------|--------|\n")
|
|
|
|
# Tri des champs pour une lecture cohérente
|
|
field_order = [
|
|
"Status", "Parent Suite", "Suite", "Sub Suite",
|
|
"Test Class", "Start Time", "Stop Time",
|
|
"Duration in ms", "Description"
|
|
]
|
|
|
|
for field in field_order:
|
|
if field in test and test[field]:
|
|
f.write(f"| {field} | {test[field]} |\n")
|
|
|
|
# Champs supplémentaires non listés
|
|
other_fields = set(test.keys()) - set(field_order)
|
|
for field in other_fields:
|
|
if test[field]:
|
|
f.write(f"| {field} | {test[field]} |\n")
|
|
|
|
f.write("\n</details>\n\n")
|
|
f.write("---\n\n") # Séparateur entre les tests
|
|
|
|
# ------------------- Main -------------------
|
|
def main():
|
|
try:
|
|
print(f"📂 Contenu du dossier allure-report: {os.listdir(ALLURE_DIR)}")
|
|
print(f"📂 Contenu de widgets: {os.listdir(WIDGETS_DIR)}")
|
|
print(f"📂 Contenu de data: {os.listdir(DATA_DIR)}")
|
|
|
|
suites_csv_df = pd.read_csv(SUITES_CSV)
|
|
with open(SUITES_JSON) as f: suites_json_data = json.load(f)
|
|
with open(SUMMARY_JSON) as f: summary = json.load(f)
|
|
|
|
generate_donut_chart(summary)
|
|
generate_detailed_test_report(suites_csv_df)
|
|
|
|
print("✅ Rapport Markdown généré : static-report.md")
|
|
|
|
except Exception as e:
|
|
print("❌ Erreur :", e)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|