diff --git a/openagent_eval/reports/base.py b/openagent_eval/reports/base.py index 03682e4..073737e 100644 --- a/openagent_eval/reports/base.py +++ b/openagent_eval/reports/base.py @@ -107,8 +107,8 @@ def generate_to_file(self, report: Any, output_path: Path | str) -> Path: """ ... - def _ensure_output_dir(self, output_path: Path | str) -> Path: - """Ensure the output directory exists. + def _prepare_output_file(self, output_path: Path | str) -> Path: + """Ensure the parent directory exists and return the resolved file path. Args: output_path: Target file path. diff --git a/openagent_eval/reports/comparison.py b/openagent_eval/reports/comparison.py index 6ddfeea..eeaeb4b 100644 --- a/openagent_eval/reports/comparison.py +++ b/openagent_eval/reports/comparison.py @@ -173,7 +173,7 @@ def generate_to_file(self, report: Any, output_path: Path | str) -> Path: Returns: Path to the written file. """ - path = self._ensure_output_dir(output_path) + path = self._prepare_output_file(output_path) if not str(path).endswith(".txt"): path = path / "comparison.txt" content = self.generate(report) diff --git a/openagent_eval/reports/html.py b/openagent_eval/reports/html.py index 19a1f84..850e157 100644 --- a/openagent_eval/reports/html.py +++ b/openagent_eval/reports/html.py @@ -152,7 +152,7 @@ def generate_to_file(self, report: Any, output_path: Path | str) -> Path: path = path / "report.html" elif path.suffix.lower() != ".html": path = path.with_suffix(".html") - path = self._ensure_output_dir(path) + path = self._prepare_output_file(path) content = self.generate(report) path.write_text(content, encoding="utf-8") return path diff --git a/openagent_eval/reports/json_report.py b/openagent_eval/reports/json_report.py index ce8020f..19a72f0 100644 --- a/openagent_eval/reports/json_report.py +++ b/openagent_eval/reports/json_report.py @@ -129,7 +129,7 @@ def generate_to_file(self, report: Any, output_path: Path | str) -> Path: path = Path(output_path) if not str(path).endswith(".json"): path = path / "report.json" - path = self._ensure_output_dir(path) + path = self._prepare_output_file(path) content = self.generate(report) path.write_text(content, encoding="utf-8") return path diff --git a/openagent_eval/reports/markdown.py b/openagent_eval/reports/markdown.py index 81ee101..4f8ba35 100644 --- a/openagent_eval/reports/markdown.py +++ b/openagent_eval/reports/markdown.py @@ -179,7 +179,7 @@ def generate_to_file(self, report: Any, output_path: Path | str) -> Path: path = Path(output_path) if not str(path).endswith(".md"): path = path / "report.md" - path = self._ensure_output_dir(path) + path = self._prepare_output_file(path) content = self.generate(report) path.write_text(content, encoding="utf-8") return path diff --git a/openagent_eval/reports/terminal.py b/openagent_eval/reports/terminal.py index 46717a9..bf9f936 100644 --- a/openagent_eval/reports/terminal.py +++ b/openagent_eval/reports/terminal.py @@ -107,7 +107,7 @@ def generate_to_file(self, report: Any, output_path: Path | str) -> Path: Returns: Path to the written file. """ - path = self._ensure_output_dir(output_path) + path = self._prepare_output_file(output_path) content = self.generate(report) path.write_text(content, encoding="utf-8") return path diff --git a/tests/unit/test_reports/test_base.py b/tests/unit/test_reports/test_base.py index 6d3d68a..94299ab 100644 --- a/tests/unit/test_reports/test_base.py +++ b/tests/unit/test_reports/test_base.py @@ -118,19 +118,19 @@ def generate_to_file(self, report: Any, output_path: Path | str) -> Path: result = report_gen.generate(evaluation_report) assert result == "test report" - def test_ensure_output_dir(self, tmp_path: Path) -> None: - """_ensure_output_dir creates parent directories.""" + def test_prepare_output_file(self, tmp_path: Path) -> None: + """_prepare_output_file creates parent directories.""" class ConcreteReport(ReportGenerator): def generate(self, report: Any) -> str: return "" def generate_to_file(self, report: Any, output_path: Path | str) -> Path: - return self._ensure_output_dir(output_path) + return self._prepare_output_file(output_path) report_gen = ConcreteReport() target = tmp_path / "subdir" / "report.txt" - result = report_gen._ensure_output_dir(target) + result = report_gen._prepare_output_file(target) assert result.parent.exists() def test_extract_metric_averages(self, pipeline_result_with_data: Any) -> None: