91 lines
5.0 KiB
Python
91 lines
5.0 KiB
Python
import unittest
|
|
|
|
from project_config.templates import BARE, branch_fault, branch_fits, branch_of, epic_branch, epic_branch_fault, fits, summary_of, title_fault, Titles
|
|
|
|
|
|
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_title_template_that_no_title_fits_or_that_splits_a_title_two_ways_is_a_fault(self) -> None:
|
|
cases = {"{summary} ": "start or end", " PAY-{id} {summary}": "start or end", "\t{summary}": "control character", "{summary}\r": "control character", "PAY-{id}\x00 {summary}": "control character", "{id}{summary}": "beside", "{summary}{id}": "beside", "PAY-{id}{summary}": "beside"}
|
|
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}", ".hidden/{id}", "{id}.", 3):
|
|
with self.subTest(template):
|
|
self.assertIsNotNone(branch_fault(template))
|
|
|
|
def test_an_epic_branch_template_holds_one_epic_and_names_a_branch_git_accepts(self) -> None:
|
|
for template in ("{epic}", "epic/{epic}"):
|
|
with self.subTest(template):
|
|
self.assertIsNone(epic_branch_fault(template))
|
|
for template in ("develop", "{epic}/{epic}", "{id}", "epic {epic}", "-{epic}", "{epic}.lock", 3):
|
|
with self.subTest(template):
|
|
self.assertIsNotNone(epic_branch_fault(template))
|
|
|
|
def test_fills_an_epic_branch_with_the_epics_key(self) -> None:
|
|
self.assertEqual(epic_branch("epic/{epic}", "ABC-123"), "epic/ABC-123")
|
|
|
|
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)
|
|
|
|
def test_a_branch_fits_its_template_where_digits_stand_for_the_id(self) -> None:
|
|
for template, branch in (("item-{id}", "item-357"), ("feature/PAY-{id}", "feature/PAY-7"), ("{id}", "12")):
|
|
with self.subTest(branch):
|
|
self.assertTrue(branch_fits(template, branch))
|
|
for template, branch in (("item-{id}", "release-review-0.3.0"), ("item-{id}", "main"), ("item-{id}", "item-"), ("item-{id}", "item-7-more"), ("a.b-{id}", "axb-7"), ("item-{id}", "")):
|
|
with self.subTest(branch):
|
|
self.assertFalse(branch_fits(template, branch))
|
|
|
|
def test_reads_a_title_through_the_commit_template_then_the_pull_request_template_then_as_its_own_summary(self) -> None:
|
|
cases = {
|
|
(Titles("{summary}", "PAY-{id} - {summary}"), "PAY-7 - Release review of 0.3.0"): "Release review of 0.3.0",
|
|
(Titles("PAY-{id} - {summary}", "{summary}"), "PAY-7 - Release review of 0.3.0"): "Release review of 0.3.0",
|
|
(Titles("PAY-{id} - {summary}", "fix: {summary} (#{id})"), "fix: Drop item 6: moot (#7)"): "Drop item 6: moot",
|
|
(Titles("PAY-{id} - {summary}", "fix: {summary} (#{id})"), "PAY-7 - Drop item 6: moot"): "Drop item 6: moot",
|
|
(Titles("PAY-{id} - {summary}", "fix: {summary} (#{id})"), "From before the templates"): "From before the templates",
|
|
(BARE, "PAY-7 - Tests"): "PAY-7 - Tests",
|
|
}
|
|
for (titles, title), summary in cases.items():
|
|
with self.subTest(title):
|
|
self.assertEqual(titles.summary(title), summary)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|