Test the plan store's refusals and failed reads and writes, and print a row's R as the plan holds it

This commit is contained in:
2026-11-14 15:26:57 +01:00
parent 0348b3fa1a
commit 812badf8b4
3 changed files with 50 additions and 7 deletions
+28
View File
@@ -1,3 +1,4 @@
import dataclasses
import pathlib
import sys
import tempfile
@@ -92,6 +93,30 @@ class FilePlan(FilePlanContract):
self.new_store().add(FIRST | {"Score": "9"}, "")
def test_refuses_a_tagline_with_a_line_break_and_a_detail_with_a_heading(self):
store = self.new_store()
id_ = self.filed(store, FIRST)
before = (self.folder / "todo.md").read_text()
broken, split = "the tagline holds a line break; keep it on one line", "the detail holds a ## or ### heading, which would split ## Details; use #### or drop the #s"
self.assertEqual(store.add(FIRST | {stores.TAGLINE: "Count\nthe runs."}, ""), Failure(broken))
self.assertEqual(store.add(FIRST, "## Why\n"), Failure(split))
self.assertEqual(store.edit(id_, {stores.TAGLINE: "Count\nthe runs."}, None), Failure(broken))
self.assertEqual(store.edit(id_, {}, "### Why\n"), Failure(split))
self.assertEqual((self.folder / "todo.md").read_text(), before)
def test_a_file_it_cannot_write_fails_naming_it(self):
store = self.new_store()
self.folder.chmod(0o555)
self.addCleanup(self.folder.chmod, 0o755)
written = store.add(FIRST, "")
assert isinstance(written, Failure), written
self.assertTrue(written.reason.startswith(f"{self.folder / 'todo.md'}: "), written.reason)
def test_a_history_it_cannot_read_fails_every_write(self):
store = dataclasses.replace(self.new_store(), history=MemoryStore(fails="no history"))
self.assertEqual(store.add(FIRST, ""), Failure("no history"))
class HeldAt(unittest.TestCase):
def test_reads_the_revisions_file_where_commits_hold_the_plan(self):
shown = []
@@ -118,3 +143,6 @@ class HeldAt(unittest.TestCase):
if __name__ == "__main__":
unittest.main()
def test_fails_where_the_revision_cannot_be_read(self):
self.assertEqual(stores.held_at("origin/main", MemoryPlan(tracked="todo.md"), "/checkout", lambda *args, cwd: Failure("no git")), Failure("no git"))
+2 -6
View File
@@ -1,5 +1,5 @@
"""How todo-item prints items: as rows of the table `rank_todo.py --help` shows, whatever backend holds the plan, without the Score a markdown plan alone has."""
from release_plan.todo_table import BLOCKED_BY, Item, OLD_SHAPE, risk, SHAPE, Shape
from release_plan.todo_table import BLOCKED_BY, Item, OLD_SHAPE, SHAPE, Shape
from release_plan.release import version
@@ -16,11 +16,7 @@ def shape_of(items: list[Item]) -> Shape:
def row(item: Item, shape: Shape) -> str:
scores = dict(item.scores)
if all(level in scores for level in ("L", "E", "I")):
# A row whose R cell rank_todo.py has not filled yet reads without one.
scores["R"] = risk(scores["L"], scores["E"], scores["I"])
named = {"ID": item.id, "Release": version(item.release), BLOCKED_BY: ", ".join(str(id_) for id_ in item.blocked_by), "Exempt": item.exempt, "Item": item.tagline, shape.goals_column: shape.write_goals(item.moves), **scores}
named = {"ID": item.id, "Release": version(item.release), BLOCKED_BY: ", ".join(str(id_) for id_ in item.blocked_by), "Exempt": item.exempt, "Item": item.tagline, shape.goals_column: shape.write_goals(item.moves), **item.scores}
return "| " + " | ".join(str(named.get(column, "")) for column in shape.columns if column != "Score") + " |"
+20 -1
View File
@@ -13,6 +13,8 @@ from todo_item import edits, main
from failure import Failure
from project_config.main import located
from release_plan import plan_file, ranking
from plan_store.stores import plan_of
from todo_item.table import table
ADD = ["add", "--release", "0.1.0", "--l", "1", "--e", "1", "--i", "1", "--s", "1", "--moves", "1 by 9", "Count the `a | b` runs."]
CHANGELOG = "# Changelog\n\n## Unreleased\n\n- Older news.\n\n## 0.1.0\n\n- First.\n"
@@ -76,7 +78,7 @@ class Help(TodoItem):
class BadArguments(TodoItem):
def test_exit_2(self):
for argv in ([], ADD[:1] + ADD[3:], ["finish"], ["show"], ["edit"], ["move", "3"], ["move", "3", "0.2.0"], ["list", "0.1.0"], ["edit", "3", "--detail", "--clear-detail"], ["edit", "3", "--release", "0.2.0"]):
for argv in ([], ADD[:1] + ADD[3:], ADD[:3] + ADD[5:], ["finish"], ["show"], ["edit"], ["move", "3"], ["move", "3", "0.2.0"], ["list", "0.1.0"], ["edit", "3", "--detail", "--clear-detail"], ["edit", "3", "--release", "0.2.0"]):
with self.subTest(argv):
self.assertEqual(self.exit_code(*argv), 2)
@@ -442,6 +444,23 @@ class Move(TodoItem):
self.assertEqual(self.todo.read_text(), before)
class OtherFile(TodoItem):
def test_ranking_works_on_the_file_it_is_given_not_the_configured_plan(self):
config = located(str(self.folder), pathlib.Path.home())
other = self.folder / "other.md"
other.write_text("not a plan\n")
self.assertNotEqual(plan_file.check_failures(other, config), [])
self.assertIsInstance(plan_file.rank_file(other, config), Failure)
self.assertEqual(plan_file.check_failures(self.todo, config), [])
class Table(unittest.TestCase):
def test_a_plan_not_yet_reshaped_lists_under_its_own_columns(self):
old = plan_of("## Items\n\n| ID | Release | Exempt | Item | R | S | C | A | G | Goals | Score |\n|---|---|---|---|---|---|---|---|---|---|---|\n| 3 | 0.2.0 | | **Do the next thing.** | 5 | 2 | 1 | 2 | 3 | 1 | 1.0 |\n")
self.assertEqual(table(old.items).split("\n")[0], "| ID | Release | Blocked by | Exempt | Item | R | S | C | A | G | Goals |")
self.assertEqual(table(old.items).split("\n")[2], "| 3 | 0.2.0 | | | **Do the next thing.** | 5 | 2 | 1 | 2 | 3 | 1 |")
class WithBullet(unittest.TestCase):
def test_keeps_a_blank_line_before_prose_under_unreleased(self):
self.assertEqual(edits.with_bullet("# Changelog\n\n## Unreleased\n\nSome note.\n", "New."), "# Changelog\n\n## Unreleased\n\n- New.\n\nSome note.\n")