90 lines
3.6 KiB
Python
90 lines
3.6 KiB
Python
import os
|
|
import json
|
|
import pandas as pd
|
|
import matplotlib.pyplot as plt
|
|
|
|
# Fichiers Allure
|
|
ALLURE_DIR = "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(WIDGETS_DIR, "suites.json")
|
|
SUMMARY_JSON = os.path.join(WIDGETS_DIR, "summary.json")
|
|
|
|
# ------------------- Graph Donut -------------------
|
|
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]
|
|
|
|
fig, ax = plt.subplots()
|
|
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")
|
|
plt.savefig("summary.png", bbox_inches="tight")
|
|
plt.close()
|
|
|
|
# ------------------- Markdown -------------------
|
|
def generate_markdown(suites_csv_df, suites_json_data):
|
|
with open("static-report.md", "w") as f:
|
|
f.write("# 🧪 Rapport de tests - CI\n\n")
|
|
f.write("\n\n")
|
|
f.write("## 📋 Détails des tests\n\n")
|
|
|
|
for index, row in suites_csv_df.iterrows():
|
|
test_id = str(row.get("uid", f"unknown-{index}"))
|
|
name = row.get("name", "Unknown")
|
|
status = row.get("status", "unknown")
|
|
duration = row.get("time", 0) / 1000
|
|
message = row.get("statusMessage", "")
|
|
|
|
json_info = suites_json_data.get(test_id, {})
|
|
description = json_info.get("description", "")
|
|
parameters = json_info.get("parameters", [])
|
|
trace = json_info.get("statusTrace", "")
|
|
|
|
f.write(f"<details>\n<summary>{name}</summary>\n\n")
|
|
f.write(f"- **Statut**: {'✅ Passed' if status == 'passed' else '❌ Failed' if status == 'failed' else status}\n")
|
|
f.write(f"- **Durée**: {round(duration, 3)} s\n")
|
|
if description:
|
|
f.write(f"- **Description**: {description.strip()}\n")
|
|
if parameters:
|
|
f.write(f"- **Paramètres**:\n")
|
|
for p in parameters:
|
|
f.write(f" - `{p.get('name')}`: `{p.get('value')}`\n")
|
|
if message:
|
|
f.write(f"- **Message**: `{message}`\n")
|
|
if trace:
|
|
f.write(f"\n<details><summary>📜 Stacktrace</summary>\n\n```\n{trace.strip()}\n```\n</details>\n")
|
|
|
|
f.write("</details>\n\n")
|
|
|
|
# ------------------- 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_markdown(suites_csv_df, suites_json_data)
|
|
|
|
print("✅ Rapport Markdown généré : static-report.md")
|
|
|
|
except Exception as e:
|
|
print("❌ Erreur :", e)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|