Test do-epic's status lines on their own

This commit is contained in:
2026-11-19 01:35:37 +01:00
parent 8e210eaa09
commit 07ef481c51
+63
View File
@@ -0,0 +1,63 @@
import datetime
import os
import pathlib
import tempfile
import unittest
from do_epic import parked, status
from do_epic.scheduler import STATE
from do_epic.test_scheduler import issue, Tmux
from failure import Failure
SINCE = 1_700_000_000
# How the status prints SINCE, in the machine's time zone.
SINCE_ON = datetime.datetime.fromtimestamp(SINCE).strftime("%Y-%m-%d %H:%M")
EPIC = "epic-ABC-12"
class TheStatusLines(unittest.TestCase):
def setUp(self) -> None:
self.home = pathlib.Path(tempfile.mkdtemp())
self.folder = self.home / STATE / "ABC-12"
def park(self, key: str, on: str, since: int | None = SINCE) -> None:
parked.park(self.folder, parked.Parked(key, f"/code/api-{key}", "7", "s", on))
if since is not None:
os.utime(parked.file_of(self.folder, key), (since, since))
def lines(self, issues: list, *windows: tuple[str, str, bool, str]) -> list[str] | Failure:
return status.lines("ABC-12", self.home, issues, Tmux(*windows))
def test_a_chunk_that_asks_says_where_to_answer_and_one_that_works_runs(self) -> None:
found = self.lines([issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api")], (EPIC, "ABC-20 ?", False, ""), (EPIC, "ABC-21", False, ""))
self.assertEqual(found, ["ABC-20 asks you: answer its question in the tmux window epic-ABC-12:ABC-20", "ABC-21 runs"])
def test_a_parked_chunk_says_what_it_awaits_and_since_when(self) -> None:
self.park("ABC-20", "an approval")
self.assertEqual(self.lines([issue("ABC-20", "repo:api")], (EPIC, "ABC-20 awaits its checks", False, "")), [f"ABC-20 waits: it is parked: its pull request #7 awaits its checks, since {SINCE_ON}"])
def test_a_parked_chunk_without_a_window_says_since_when_and_how_to_start_it_again(self) -> None:
self.park("ABC-20", "an approval")
self.assertEqual(self.lines([issue("ABC-20", "repo:api")]), [f"ABC-20 waits: it is parked: its pull request #7 awaits an approval, since {SINCE_ON}, and its window stopped; run `do-epic ABC-12` to start it again"])
def test_a_stopped_chunk_and_one_not_started_say_so(self) -> None:
found = self.lines([issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api")], (EPIC, "ABC-20", True, ""))
self.assertEqual(found, ["ABC-20 waits: its window stopped; run `do-epic ABC-12` to start it again", "ABC-21 waits: it has not started; `do-epic ABC-12` starts it once the epic and its repo have room"])
def test_a_human_task_and_a_blocked_issue_say_why_they_wait(self) -> None:
found = self.lines([issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api", blockers=("ABC-20",)), issue("ABC-22", "do-epic-human")], (EPIC, "ABC-20", False, ""))
self.assertEqual(found, ["ABC-20 runs", "ABC-21 waits: ABC-20 blocks it", "ABC-22 waits: it is a human's task"])
def test_a_parked_chunk_that_cannot_be_read_is_a_failure(self) -> None:
(self.folder / parked.FOLDER).mkdir(parents=True)
(self.folder / parked.FOLDER / "ABC-20.json").write_text("{", encoding="utf-8")
self.assertIsInstance(self.lines([issue("ABC-20", "repo:api")]), Failure)
class TheTimeSinceParking(unittest.TestCase):
def test_is_empty_where_the_chunks_file_is_gone(self) -> None:
self.assertEqual(status.since(pathlib.Path(tempfile.mkdtemp()), parked.Parked("ABC-20", "/code/api", "7", "s", "an approval")), "")
if __name__ == "__main__":
unittest.main()