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
+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")