D25: config_cmd.py → пакет commands/config/ по семействам сущностей (19 подкоманд, поверхность без изменений)
This commit is contained in:
1 parent
bd23b03c08
commit
3d4ee910b4
16 files changed
+706
-450
No files matched your search
@@ -65,3 +65,37 @@ class TestNoCliDependency:
|
||||
if imports:
|
||||
offenders[str(path.relative_to(REPO_ROOT))] = imports
|
||||
assert not offenders, f"infrastructure/ai импортирует CLI: {offenders}"
|
||||
|
||||
|
||||
COMMANDS_ROOT = CLI_ROOT / "commands"
|
||||
CONFIG_PKG = COMMANDS_ROOT / "config"
|
||||
|
||||
|
||||
def _typer_instantiations(path: Path) -> list[int]:
|
||||
"""Номера строк, где модуль создаёт `typer.Typer(...)` (D3: мёртвые Typer'ы)."""
|
||||
tree = ast.parse(path.read_text(encoding="utf-8"), filename=str(path))
|
||||
lines = []
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute) and node.func.attr == "Typer":
|
||||
lines.append(node.lineno)
|
||||
return lines
|
||||
|
||||
|
||||
class TestTyperRegistration:
|
||||
"""D25: один Typer-объект на пакет `config`, остальные модули только декорируют."""
|
||||
|
||||
def test_config_package_creates_exactly_one_typer(self):
|
||||
hits = {path: _typer_instantiations(path) for path in sorted(CONFIG_PKG.rglob("*.py"))}
|
||||
hits = {path: lines for path, lines in hits.items() if lines}
|
||||
assert set(hits) == {CONFIG_PKG / "_app.py"}, f"Typer создаётся не только в _app.py: {sorted(map(str, hits))}"
|
||||
assert len(hits[CONFIG_PKG / "_app.py"]) == 1
|
||||
|
||||
def test_other_command_modules_do_not_create_typer_apps(self):
|
||||
offenders = {}
|
||||
for path in sorted(COMMANDS_ROOT.rglob("*.py")):
|
||||
if CONFIG_PKG in path.parents:
|
||||
continue
|
||||
lines = _typer_instantiations(path)
|
||||
if lines:
|
||||
offenders[str(path.relative_to(REPO_ROOT))] = lines
|
||||
assert not offenders, f"модули команд создают собственные Typer: {offenders}"
|
||||
Reference in new issue
Block a user