Files
dl-organizer/tests/test_docs_consistency.py
T
windyboyandClaude Sonnet 4.5 9814b2b917 feat: enable anime parsing and organization with dedicated templates
Anime files with SxxEyy format are now parsed and organized into
anime-specific directories using configurable templates. Files with
absolute episode numbering (no season info) are marked needs_review
for manual handling. Also removes unused imports flagged by ruff.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-09-27 11:08:15 +08:00

82 lines
2.1 KiB
Python

"""Verify vlm commands referenced in documentation exist in the CLI registry."""
from __future__ import annotations
import re
from pathlib import Path
import pytest
from vlm.cli import main
REPO_ROOT = Path(__file__).resolve().parent.parent
DOC_GLOBS = [
"README.md",
"CLAUDE.md",
"AGENTS.md",
"skills/**/*.md",
]
COMMAND_PATTERN = re.compile(
r"^(?:uv run )?(?:\$ )?vlm\s+(.+)$", re.MULTILINE
)
def _extract_doc_commands() -> list[str]:
commands: list[str] = []
for pattern in DOC_GLOBS:
for path in REPO_ROOT.glob(pattern):
text = path.read_text(encoding="utf-8")
for match in COMMAND_PATTERN.finditer(text):
raw = match.group(1).strip()
raw = raw.rstrip("\\").strip()
if raw.startswith("#") or not raw:
continue
commands.append(raw)
return commands
def _cli_command_names() -> dict[str, list[str]]:
result: dict[str, list[str]] = {}
for name, cmd in main.commands.items():
result[name] = []
if hasattr(cmd, "commands"):
result[name] = list(cmd.commands.keys())
return result
@pytest.mark.parametrize(
"raw_cmd",
sorted(set(_extract_doc_commands())),
ids=lambda c: c[:60],
)
def test_documented_command_exists(raw_cmd: str):
parts = raw_cmd.split()
if not parts:
pytest.skip("empty command")
first = parts[0]
if first in ("--help", "-h"):
return
registry = _cli_command_names()
if first not in registry:
pytest.fail(f"Documented command 'vlm {first}' not in CLI registry")
if len(parts) > 1:
sub = parts[1]
if sub.startswith("-"):
return
subcommands = registry.get(first, [])
if subcommands and sub not in subcommands:
pytest.fail(
f"Documented subcommand 'vlm {first} {sub}' "
f"not in CLI registry (available: {subcommands})"
)
def test_fake_command_is_caught():
registry = _cli_command_names()
assert "nonexistent-command-xyz" not in registry