From f28b2b107302761ff450cff5788f045476916154 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Tue, 24 Nov 2026 03:46:21 +0100 Subject: [PATCH] feat: hold each package to its naming style --- tests/test_layers.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test_layers.py b/tests/test_layers.py index 612827dc9..d2512a0b8 100644 --- a/tests/test_layers.py +++ b/tests/test_layers.py @@ -11,6 +11,7 @@ from __future__ import annotations import tests import ast +import re import sys import unittest from pathlib import Path @@ -338,5 +339,37 @@ class ThinCommands(unittest.TestCase): self.assertEqual(sorted(set(found)), [], "import it from the package that holds it") +# How a module is named in each package: the domain packages join the words +# of a name (crossreflaunchers), the plugin packages end a module in its kind +# (batocera_exporter), scraper/ and installer/ separate words with an +# underscore. One style per package, so a name says where it belongs. +PLUGIN_SUFFIXES = {"exporter": "_exporter"} +UNDERSCORED = frozenset({"scraper"}) + + +class ModuleNames(unittest.TestCase): + def test_each_package_keeps_one_naming_style(self): + found = [] + for path in sorted(SCRIPTS.rglob("*.py")): + if "__pycache__" in path.parts or path.stem.startswith("_"): + continue + parts = path.relative_to(SCRIPTS).parts + if len(parts) == 1 or parts[0] in UNDERSCORED: + rule = r"[a-z][a-z0-9_]*" + elif parts[0] in PLUGIN_SUFFIXES: + rule = r"[a-z][a-z0-9]*(" + PLUGIN_SUFFIXES[parts[0]] + ")?" + else: + rule = r"[a-z][a-z0-9]*" + if not re.fullmatch(rule, path.stem): + found.append(str(path.relative_to(SCRIPTS))) + self.assertEqual(found, [], "name it as the other modules of its package") + + def test_installer_modules_separate_their_words(self): + installer = SCRIPTS.parent / "installer" + found = [p.name for p in sorted(installer.glob("*.py")) + if not p.stem.startswith("_") and not re.fullmatch(r"[a-z][a-z0-9_]*", p.stem)] + self.assertEqual(found, []) + + if __name__ == "__main__": unittest.main()