Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions openagent_eval/reports/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,12 @@ def generate_to_file(self, report: Any, output_path: Path | str) -> Path:
Returns:
Path to the written file.
"""
path = self._prepare_output_file(output_path)
if not str(path).endswith(".txt"):
path = Path(output_path)
if path.suffix == "":
path = path / "comparison.txt"
elif path.suffix.lower() != ".txt":
path = path.with_suffix(".txt")
path = self._prepare_output_file(path)
content = self.generate(report)
path.write_text(content, encoding="utf-8")
return path
4 changes: 3 additions & 1 deletion openagent_eval/reports/json_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ def generate_to_file(self, report: Any, output_path: Path | str) -> Path:
Path to the written file.
"""
path = Path(output_path)
if not str(path).endswith(".json"):
if path.suffix == "":
path = path / "report.json"
elif path.suffix.lower() != ".json":
path = path.with_suffix(".json")
path = self._prepare_output_file(path)
content = self.generate(report)
path.write_text(content, encoding="utf-8")
Expand Down
4 changes: 3 additions & 1 deletion openagent_eval/reports/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,10 @@ def generate_to_file(self, report: Any, output_path: Path | str) -> Path:
Path to the written file.
"""
path = Path(output_path)
if not str(path).endswith(".md"):
if path.suffix == "":
path = path / "report.md"
elif path.suffix.lower() != ".md":
path = path.with_suffix(".md")
path = self._prepare_output_file(path)
content = self.generate(report)
path.write_text(content, encoding="utf-8")
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/test_reports/test_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ def test_generate_to_file(
content = result_path.read_text(encoding="utf-8")
assert "Experiment Comparison Report" in content

def test_generate_to_file_replaces_non_txt_extension(
self, comparison: Any, tmp_path: Path
) -> None:
"""generate_to_file() replaces non-.txt suffixes with .txt."""
report = ComparisonReport()
output_path = tmp_path / "comparison.log"
result_path = report.generate_to_file(comparison, output_path)

assert result_path == tmp_path / "comparison.txt"
assert result_path.exists()
content = result_path.read_text(encoding="utf-8")
assert "Experiment Comparison Report" in content

def test_generate_to_file_creates_directory(
self, comparison: Any, tmp_path: Path
) -> None:
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/test_reports/test_json_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ def test_generate_to_file_adds_extension(
assert result_path.exists()
assert str(result_path).endswith(".json")

def test_generate_to_file_replaces_non_json_extension(
self, evaluation_report: Any, tmp_path: Path
) -> None:
"""generate_to_file() replaces non-.json suffixes with .json."""
report = JSONReport()
output_path = tmp_path / "report.txt"
result_path = report.generate_to_file(evaluation_report, output_path)

assert result_path == tmp_path / "report.json"
assert result_path.exists()
data = json.loads(result_path.read_text(encoding="utf-8"))
assert "metadata" in data

def test_generate_to_file_creates_directory(
self, evaluation_report: Any, tmp_path: Path
) -> None:
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/test_reports/test_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ def test_generate_to_file_adds_extension(
assert result_path.exists()
assert str(result_path).endswith(".md")

def test_generate_to_file_replaces_non_md_extension(
self, evaluation_report: Any, tmp_path: Path
) -> None:
"""generate_to_file() replaces non-.md suffixes with .md."""
report = MarkdownReport()
output_path = tmp_path / "report.txt"
result_path = report.generate_to_file(evaluation_report, output_path)

assert result_path == tmp_path / "report.md"
assert result_path.exists()
content = result_path.read_text(encoding="utf-8")
assert "## Summary" in content

def test_generate_to_file_creates_directory(
self, evaluation_report: Any, tmp_path: Path
) -> None:
Expand Down
Loading