global_report.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # Apache License, Version 2.0
  2. #
  3. # Generate a HTML page that links to all test reports.
  4. import glob
  5. import os
  6. import pathlib
  7. def _write_html(output_dir):
  8. combined_reports = ""
  9. # Gather intermediate data for all tests and combine into one HTML file.
  10. categories = sorted(glob.glob(os.path.join(output_dir, "report", "*")))
  11. for category in categories:
  12. category_name = os.path.basename(category)
  13. combined_reports += "<h3>" + category_name + "</h3>\n"
  14. reports = sorted(glob.glob(os.path.join(category, "*.data")))
  15. for filename in reports:
  16. filepath = os.path.join(output_dir, filename)
  17. combined_reports += pathlib.Path(filepath).read_text()
  18. combined_reports += "<br/>\n";
  19. html = """
  20. <html>
  21. <head>
  22. <title>{title}</title>
  23. <style>
  24. .ok {{ color: green; }}
  25. .failed {{ color: red; }}
  26. .none {{ color: #999; }}
  27. </style>
  28. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  29. </head>
  30. <body>
  31. <div class="container">
  32. <br/>
  33. <h1>{title}</h1>
  34. {combined_reports}
  35. <br/>
  36. </div>
  37. </body>
  38. </html>
  39. """ . format(title="Blender Test Reports",
  40. combined_reports=combined_reports)
  41. filepath = os.path.join(output_dir, "report.html")
  42. pathlib.Path(filepath).write_text(html)
  43. def add(output_dir, category, name, filepath, failed=None):
  44. # Write HTML for single test.
  45. if failed is None:
  46. status = "none"
  47. elif failed:
  48. status = "failed"
  49. else:
  50. status = "ok"
  51. html = """
  52. <span class="{status}">&#11044;</span>
  53. <a href="file://{filepath}">{name}</a><br/>
  54. """ . format(status=status,
  55. name=name,
  56. filepath=filepath)
  57. dirpath = os.path.join(output_dir, "report", category);
  58. os.makedirs(dirpath, exist_ok=True)
  59. filepath = os.path.join(dirpath, name + ".data")
  60. pathlib.Path(filepath).write_text(html)
  61. # Combined into HTML, each time so we can see intermediate results
  62. # while tests are still running.
  63. _write_html(output_dir)