Files
claude-config/bin/loop_claude/test_routed_item.py
T

54 lines
3.3 KiB
Python

import pathlib
import re
import sys
import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from failure import Failure
from release_plan.release_standing import LastCut
import loop_claude.routed_item
from loop_claude.doubles import NO_CUT, TODO
from plan_store.todo_md import plan_of
def routed_item(todo, cut):
"""loop_claude.routed_item.routed_item for the plan a todo.md's text holds."""
return loop_claude.routed_item.routed_item(plan_of(todo), cut)
class RoutedItem(unittest.TestCase):
def test_routes_on_the_next_releases_top_item_that_waits_on_no_question(self):
self.assertEqual(routed_item(TODO, NO_CUT).id, 3)
self.assertIsNone(routed_item(TODO.replace("| | **Do", "| question | **Do"), NO_CUT))
self.assertIsNone(routed_item("# todo\n", NO_CUT))
self.assertIsNone(routed_item(TODO[:TODO.index("| 7 |")], NO_CUT))
old_shape = "## 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 | 3 | 6 | 8 | 9 | 1 | 25 |\n"
self.assertIsNone(routed_item(old_shape, NO_CUT))
self.assertEqual(routed_item(TODO.replace("| 4 | 2 | 3 |", "| x | 2 | 3 |"), NO_CUT), Failure("item 3's L 'x' is not a whole number from 1 to 4"))
def test_routes_on_no_item_where_the_release_after_the_last_cut_has_none(self):
self.assertEqual(routed_item(TODO, LastCut("v0.1.0", "", 3, [TODO])).id, 3)
# Someone cut 0.2.0 while it held items: they count as 0.3.0's, the next release, and where no later release is known, no item routes.
self.assertEqual(routed_item(TODO, LastCut("v0.2.0", "", 3, [TODO])).id, 3)
self.assertIsNone(routed_item(re.sub(r"(?m)^\| \d+ \| 0\.3\.0 \|.*\n", "", TODO), LastCut("v0.2.0", "", 3, [])))
later_only = TODO[:TODO.index("| 7 |")] + TODO[TODO.index("| 1 | 0.3.0 |"):]
self.assertIsNone(routed_item(later_only, LastCut("v0.1.0", "", 3, [TODO])))
self.assertIsNone(routed_item(later_only, LastCut("v0.1.0", "", 0, [TODO])))
self.assertEqual(routed_item(later_only, LastCut("v0.2.0", "", 3, [later_only])).id, 1)
def test_routes_past_an_item_a_waiting_item_blocks(self):
todo = "## Items\n\n| ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score |\n|---|---|---|---|---|---|---|---|---|---|---|---|\n| 7 | 0.2.0 | | question | **Ask first.** | 4 | 3 | 5 | 10 | 1 | 1 by 9 | 30 |\n| 8 | 0.2.0 | 7 | | **Use the answer.** | 1 | 1 | 1 | 1 | 1 | 1 by 9 | 30 |\n| 9 | 0.2.0 | 8 | | **Build on it.** | 1 | 1 | 1 | 1 | 1 | 1 by 9 | 30 |\n| 3 | 0.2.0 | | | **Do the next thing.** | 4 | 2 | 3 | 7 | 3 | 1 by 9 | 25 |\n"
self.assertEqual(routed_item(todo, NO_CUT).id, 3)
self.assertEqual(routed_item(todo.replace("| question |", "| |"), NO_CUT).id, 7)
first = "| 7 | 0.2.0 | | question | **Ask first.** | 4 | 3 | 5 | 10 | 1 | 1 by 9 | 30 |\n"
self.assertEqual(routed_item(todo.replace(first, "") + first, NO_CUT).id, 3)
def test_routes_nothing_on_an_item_without_e_or_i(self):
without_i = TODO.replace("| E | I | R |", "| E | R |").replace("|---|---|---|---|---|---|---|---|---|---|---|", "|---|---|---|---|---|---|---|---|---|---|").replace("| 4 | 3 | 5 | 10 |", "| 4 | 3 | 10 |").replace("| 4 | 2 | 3 | 7 |", "| 4 | 2 | 7 |").replace("| 1 | 1 | 1 | 1 |", "| 1 | 1 | 1 |")
self.assertIsNone(routed_item(without_i, NO_CUT))
if __name__ == "__main__":
unittest.main()