Files
claude-config/bin/review_rules/test_review_folder.py
T

43 lines
2.0 KiB
Python

import pathlib
import sys
import tempfile
import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from failure import Failure
from review_rules.round_titles import Findings
from review_rules.review_folder import findings_in, review_folder, standing_report
class ReviewFolder(unittest.TestCase):
def test_keys_a_worktree_under_home_by_its_path_relative_to_home(self):
self.assertEqual(review_folder("/h", "/h/code/proj-item-3"), "/h/.local/state/larv-review/code/proj-item-3")
def test_keys_a_worktree_outside_home_by_its_path_relative_to_the_root(self):
self.assertEqual(review_folder("/h", "/srv/proj-item-3"), "/h/.local/state/larv-review/srv/proj-item-3")
self.assertEqual(review_folder("/h", "/hx/proj"), "/h/.local/state/larv-review/hx/proj", "a sibling of home that shares its prefix is outside it")
class RoundReport(unittest.TestCase):
def test_counts_the_rounds_report_or_its_rerun_one_rung_up_where_there_is_one(self):
with tempfile.TemporaryDirectory() as temp:
folder = pathlib.Path(temp)
(folder / "prose-round-1.md").write_text("BLOCK\n\n### 🟡 a\n")
self.assertEqual(findings_in(standing_report(folder, "prose", 1)), Findings(0, 1, 0))
(folder / "prose-round-1-rerun.md").write_text("BLOCK\n\n### 🔴 [misread] a\n")
self.assertEqual(findings_in(standing_report(folder, "prose", 1)), Findings(1, 0, 1))
def test_names_a_missing_report(self):
with tempfile.TemporaryDirectory() as temp:
missing = findings_in(standing_report(pathlib.Path(temp), "prose", 2))
self.assertIsInstance(missing, Failure)
self.assertEqual(missing.reason, f"no report at {temp}/prose-round-2.md")
def test_names_a_report_it_cannot_read(self):
with tempfile.TemporaryDirectory() as temp:
(pathlib.Path(temp) / "prose-round-1.md").mkdir()
unread = findings_in(standing_report(pathlib.Path(temp), "prose", 1))
self.assertIsInstance(unread, Failure)
self.assertTrue(unread.reason.startswith(f"could not read {temp}/prose-round-1.md: "), unread.reason)