test(scripts): run SelectTest on a fixture tree
Build / build (pull_request) Successful in 12s
Lint / lint (pull_request) Successful in 44s
Molecule / molecule (pull_request) Successful in 1m21s

SelectTest called select() against the repository itself, so its expectations
depended on which real roles use which: with gitea using fail2ban, a change to
fail2ban also selects gitea, and test_two_roles failed with "role without a
molecule scenario". The selection tests now run on a temporary tree that holds
the roles of ALL and no use of one role by another, like UsersTest, which
covers the users.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
This commit is contained in:
Defame1297andClaude Opus 5.5 committed 2026-11-21 21:59:33 +00:00
1 parent f060461152
commit a197536ba6
1 file changed
+26 -10
+26 -10
View File
@@ -98,24 +98,40 @@ ALL = [
class SelectTest(unittest.TestCase):
# A fixture tree with the roles of ALL and no use of one role by another, so that the
# expectations do not depend on which roles of this repository use which (UsersTest
# covers the users).
def setUp(self):
tmp = tempfile.TemporaryDirectory()
self.addCleanup(tmp.cleanup)
self.root = tmp.name
for scenario in ALL:
pathlib.Path(self.root, scenario).mkdir(parents=True)
pathlib.Path(self.root, scenario, "molecule.yml").write_text("---\n")
if scenario.startswith("roles/"):
tasks = pathlib.Path(self.root, *scenario.split("/")[:2], "tasks")
tasks.mkdir()
(tasks / "main.yml").write_text("---\n")
def select(self, changed):
return sel.select(ALL, changed, self.root)
def test_role_change_selects_only_that_role(self):
chosen, _reason = sel.select(
ALL,
chosen, _reason = self.select(
["roles/docker/tasks/main.yml", "roles/docker/molecule/default/verify.yml"],
)
self.assertEqual(chosen, ["roles/docker/molecule/default"])
def test_two_roles(self):
chosen, _reason = sel.select(
ALL, ["roles/fail2ban/defaults/main.yml", "roles/docker/meta/main.yml"]
chosen, _reason = self.select(
["roles/fail2ban/defaults/main.yml", "roles/docker/meta/main.yml"]
)
self.assertEqual(
chosen, ["roles/docker/molecule/default", "roles/fail2ban/molecule/default"]
)
def test_ignored_only_selects_nothing(self):
chosen, _reason = sel.select(
ALL,
chosen, _reason = self.select(
[
"docs/x.md",
"changelogs/fragments/a.yml",
@@ -126,7 +142,7 @@ class SelectTest(unittest.TestCase):
self.assertEqual(chosen, [])
def test_ignored_does_not_mask_a_role(self):
chosen, _reason = sel.select(ALL, ["docs/x.md", "roles/docker/tasks/main.yml"])
chosen, _reason = self.select(["docs/x.md", "roles/docker/tasks/main.yml"])
self.assertEqual(chosen, ["roles/docker/molecule/default"])
def test_anything_else_selects_everything(self):
@@ -141,15 +157,15 @@ class SelectTest(unittest.TestCase):
"new_top_level_file",
"roles/README.md",
):
chosen, _reason = sel.select(ALL, ["roles/docker/tasks/main.yml", path])
chosen, _reason = self.select(["roles/docker/tasks/main.yml", path])
self.assertEqual(chosen, ALL, path)
def test_deleted_role_selects_nothing_of_its_own(self):
chosen, _reason = sel.select(ALL, ["roles/gone/tasks/main.yml"])
chosen, _reason = self.select(["roles/gone/tasks/main.yml"])
self.assertEqual(chosen, [])
def test_ignored_patterns_are_not_prefix_tricks(self):
chosen, _reason = sel.select(ALL, ["docsx/y"])
chosen, _reason = self.select(["docsx/y"])
self.assertEqual(chosen, ALL)