test(integration): ignore **pycache** directories in role validation tests

https://chatgpt.com/share/69481867-784c-800f-ab60-50ce3b241dd4
This commit is contained in:
kevinveenbirkenbach committed 2025-12-21 16:55:06 +01:00
1 parent 30d557ef0d
commit 38c8b59fe0
2 files changed
+21 -7

No files matched your search

+15 -5
View File
@@ -1,18 +1,28 @@
import os
import unittest
ROLES_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../roles"))
ROLES_DIR = os.path.abspath(
os.path.join(os.path.dirname(__file__), "../../roles")
)
class TestRolesHaveMetaMain(unittest.TestCase):
def test_each_role_has_meta_main(self):
missing_meta = []
for role in os.listdir(ROLES_DIR):
# Ignore Python cache and hidden directories
if role.startswith(".") or role == "__pycache__":
continue
role_path = os.path.join(ROLES_DIR, role)
if os.path.isdir(role_path):
meta_main = os.path.join(role_path, "meta", "main.yml")
if not os.path.isfile(meta_main):
missing_meta.append(role)
if not os.path.isdir(role_path):
continue
meta_main = os.path.join(role_path, "meta", "main.yml")
if not os.path.isfile(meta_main):
missing_meta.append(role)
if missing_meta:
self.fail(
"The following roles are missing meta/main.yml:\n"
+6 -2
View File
@@ -10,19 +10,23 @@ ROLE_NAME_PATTERN = re.compile(r"^[a-z0-9-]+(?:_[a-z0-9-]+)?$")
class TestRoleNames(unittest.TestCase):
def test_role_names_follow_naming_convention(self):
# go up from tests/integration/test_roles_naming.py to project root, then into roles/
roles_dir = Path(__file__).resolve().parents[2] / "roles"
self.assertTrue(
roles_dir.is_dir(), f"'roles/' directory not found at {roles_dir}"
)
invalid_names = []
for role_path in roles_dir.iterdir():
if not role_path.is_dir():
# skip non-directories
continue
name = role_path.name
# Ignore Python cache and hidden directories
if name.startswith(".") or name == "__pycache__":
continue
if not ROLE_NAME_PATTERN.fullmatch(name):
invalid_names.append(name)