51 lines
2.4 KiB
Python
51 lines
2.4 KiB
Python
import unittest
|
|
|
|
from project_config.templates import branch_fault, branch_of, fits, summary_of, title_fault
|
|
|
|
|
|
class TitleTest(unittest.TestCase):
|
|
def test_a_title_template_holds_one_summary_and_at_most_one_id(self) -> None:
|
|
for template in ("{summary}", "PAY-{id} - {summary}", "fix: {summary} (#{id})"):
|
|
with self.subTest(template):
|
|
self.assertIsNone(title_fault(template))
|
|
cases = {"PAY-{id}": "{summary}", "{summary} {summary}": "{summary}", "{id} {id} {summary}": "{id}", "{ID} {summary}": "{ID}", "{summary} }": "}", "{summary}\nmore": "one line", "": "{summary}", 3: "text"}
|
|
for template, named in cases.items():
|
|
with self.subTest(template):
|
|
fault = title_fault(template)
|
|
assert fault is not None
|
|
self.assertIn(named, fault)
|
|
|
|
def test_a_branch_template_holds_one_id_and_names_a_branch_git_accepts(self) -> None:
|
|
for template in ("item-{id}", "feature/PAY-{id}", "{id}"):
|
|
with self.subTest(template):
|
|
self.assertIsNone(branch_fault(template))
|
|
for template in ("feature", "{id}-{summary}", "{id}/{id}", "feature/ PAY-{id}", "-{id}", "a..b{id}", "{id}.lock", "/{id}", "{id}/", "a~{id}", 3):
|
|
with self.subTest(template):
|
|
self.assertIsNotNone(branch_fault(template))
|
|
|
|
def test_fills_a_branch_with_the_items_id(self) -> None:
|
|
self.assertEqual(branch_of("item-{id}", 357), "item-357")
|
|
self.assertEqual(branch_of("feature/PAY-{id}", 357), "feature/PAY-357")
|
|
|
|
def test_reads_the_summary_out_of_a_title_that_fits(self) -> None:
|
|
cases = {
|
|
("{summary}", "Answer prose round 1: 0 🔴, 0 🟡 (0 misread)"): "Answer prose round 1: 0 🔴, 0 🟡 (0 misread)",
|
|
("PAY-{id} - {summary}", "PAY-357 - Drop item 69: no longer wanted"): "Drop item 69: no longer wanted",
|
|
("fix: {summary} (#{id})", "fix: Regression tests (#357)"): "Regression tests",
|
|
("[{id}] {summary}", "[357] a (b) [c]"): "a (b) [c]",
|
|
}
|
|
for (template, title), summary in cases.items():
|
|
with self.subTest(title):
|
|
self.assertTrue(fits(template, title))
|
|
self.assertEqual(summary_of(template, title), summary)
|
|
|
|
def test_a_title_that_does_not_fit_is_its_own_summary(self) -> None:
|
|
for template, title in (("PAY-{id} - {summary}", "Answer prose round 1: 0 🔴"), ("PAY-{id} - {summary}", "PAY-x - Tests"), ("PAY-{id} - {summary}", "PAY-357 - "), ("fix: {summary} (#{id})", "fix: Tests")):
|
|
with self.subTest(title):
|
|
self.assertFalse(fits(template, title))
|
|
self.assertEqual(summary_of(template, title), title)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|