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: 6 additions & 1 deletion openagent_eval/reports/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,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)
path = Path(output_path)
if path.suffix == "":
path = path / "report.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
Expand Down
39 changes: 38 additions & 1 deletion tests/unit/test_reports/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,49 @@ def test_generate_to_file_creates_directory(
) -> None:
"""generate_to_file() creates parent directories."""
report = TerminalReport()
output_path = tmp_path / "subdir" / "report.txt"
output_path = Path(tmp_path / "subdir" / "report.txt")
result_path = report.generate_to_file(evaluation_report, output_path)

assert result_path.exists()
assert result_path.parent.exists()

def test_generate_to_file_defaults_to_txt(
self, evaluation_report: Any, tmp_path: Path
) -> None:
"""generate_to_file() appends report.txt when no extension is given."""
report = TerminalReport()
output_path = tmp_path / "my_report"
result_path = report.generate_to_file(evaluation_report, output_path)

assert result_path.name == "report.txt"
assert result_path.exists()
content = result_path.read_text(encoding="utf-8")
assert "SUMMARY" in content

def test_generate_to_file_normalizes_wrong_suffix(
self, evaluation_report: Any, tmp_path: Path
) -> None:
"""generate_to_file() normalizes a non-.txt suffix to .txt."""
report = TerminalReport()
output_path = tmp_path / "my_report.log"
result_path = report.generate_to_file(evaluation_report, output_path)

assert result_path.suffix.lower() == ".txt"
assert result_path.exists()
content = result_path.read_text(encoding="utf-8")
assert "SUMMARY" in content

def test_generate_to_file_keeps_txt_suffix(
self, evaluation_report: Any, tmp_path: Path
) -> None:
"""generate_to_file() preserves an explicit .txt path."""
report = TerminalReport()
output_path = tmp_path / "explicit.txt"
result_path = report.generate_to_file(evaluation_report, output_path)

assert result_path.name == "explicit.txt"
assert result_path.exists()

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