1717import logging
1818from pathlib import Path
1919
20+ import jinja2
21+
2022from .system import System
2123from .test_scenario import TestRun , TestScenario
2224
@@ -44,15 +46,41 @@ def generate(self) -> None:
4446 Args:
4547 test_scenario (TestScenario): The scenario containing tests.
4648 """
49+ self .generate_scenario_report ()
50+
4751 for tr in self .test_scenario .test_runs :
4852 test_output_dir = self .results_root / tr .name
4953 if not test_output_dir .exists () or not test_output_dir .is_dir ():
5054 logging .warning (f"Directory '{ test_output_dir } ' not found." )
5155 continue
5256
53- self ._generate_test_report (test_output_dir , tr )
57+ self .generate_per_case_reports (test_output_dir , tr )
5458
55- def _generate_test_report (self , directory_path : Path , tr : TestRun ) -> None :
59+ def generate_scenario_report (self ) -> None :
60+ template = jinja2 .Environment (loader = jinja2 .FileSystemLoader ("src/cloudai/util" )).get_template (
61+ "general-report.jinja2"
62+ )
63+
64+ results = {}
65+ for tr in self .test_scenario .test_runs :
66+ for iter in range (tr .iterations ):
67+ run_dir = self .results_root / tr .name / f"{ iter } "
68+ if run_dir .exists ():
69+ results .setdefault (
70+ tr .name + f"{ iter } " , {"logs_path" : f"./{ run_dir .relative_to (self .results_root )} " }
71+ )
72+
73+ report = template .render (
74+ test_scenario = self .test_scenario ,
75+ tr_results = results ,
76+ )
77+ report_path = self .results_root / f"{ self .test_scenario .name } .html"
78+ with report_path .open ("w" ) as f :
79+ f .write (report )
80+
81+ logging .info (f"Generated scenario report at { report_path } " )
82+
83+ def generate_per_case_reports (self , directory_path : Path , tr : TestRun ) -> None :
5684 """
5785 Generate reports for a test by iterating through subdirectories within the directory path.
5886
@@ -71,7 +99,7 @@ def _generate_test_report(self, directory_path: Path, tr: TestRun) -> None:
7199 tr .output_path = subdir
72100
73101 if not rgs .can_handle_directory ():
74- logging .warning (f"Skipping '{ tr .output_path } ', can't handle with " f"strategy={ reporter } ." )
102+ logging .warning (f"Skipping '{ tr .output_path } ', can't handle with " f"strategy={ reporter . __name__ } ." )
75103 continue
76104
77105 rgs .generate_report ()
0 commit comments