| import json |
| import tempfile |
| import unittest |
| from pathlib import Path |
|
|
| from test_cli import _read_final_answer_from_raw, _read_final_answer_from_report |
|
|
|
|
| class CliHelperTests(unittest.TestCase): |
| def test_read_final_answer_from_raw_returns_last_iteration_answer(self): |
| with tempfile.TemporaryDirectory() as tmpdir: |
| path = Path(tmpdir) / "result.json" |
| path.write_text(json.dumps({ |
| "iterations": [ |
| {"t": 1, "answer": "first"}, |
| {"t": 2, "answer": "final answer"}, |
| ] |
| }), encoding="utf-8") |
|
|
| self.assertEqual(_read_final_answer_from_raw(str(path)), "final answer") |
|
|
| def test_read_final_answer_from_raw_handles_missing_or_invalid_files(self): |
| self.assertEqual(_read_final_answer_from_raw("/tmp/does-not-exist.json"), "") |
|
|
| with tempfile.TemporaryDirectory() as tmpdir: |
| path = Path(tmpdir) / "broken.json" |
| path.write_text("{not json", encoding="utf-8") |
| self.assertEqual(_read_final_answer_from_raw(str(path)), "") |
|
|
| def test_read_final_answer_from_report_extracts_blockquoted_answer(self): |
| report = ( |
| "## Summary\n\n" |
| "Something.\n\n" |
| "## Generated Answer\n\n" |
| "> Line one\n" |
| "> Line two\n\n" |
| "## Next Section\n\n" |
| "Trailing content." |
| ) |
| self.assertEqual(_read_final_answer_from_report(report), "Line one\nLine two") |
|
|
| def test_read_final_answer_from_report_returns_empty_when_missing(self): |
| self.assertEqual(_read_final_answer_from_report("## Summary\n\nNothing here."), "") |
|
|