Skip to content

Commit 157a238

Browse files
committed
Fix/cleanup documented controllers test
1 parent 8afb668 commit 157a238

File tree

1 file changed

+9
-41
lines changed

1 file changed

+9
-41
lines changed

tests/pytest/test_controller_documentation.py

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
import ast
3+
import importlib
44
from pathlib import Path
55
from typing import Set
66

@@ -11,50 +11,18 @@
1111

1212
CONTROLLER_DIR = root / "shiny/playwright/controller"
1313
DOCS_CONFIG = root / "docs/_quartodoc-testing.yml"
14-
SKIP_PATTERNS = {"Base", "Container", "Label", "StyleM"}
15-
CONTROLLER_BASE_PATTERNS = {
16-
"Base",
17-
"Container",
18-
"Label",
19-
"StyleM",
20-
"WidthLocM",
21-
"InputActionButton",
22-
"UiBase",
23-
"UiWithLabel",
24-
"UiWithContainer",
25-
}
26-
27-
28-
def _is_valid_controller_class(node: ast.ClassDef) -> bool:
29-
class_name = node.name
30-
base_names = {ast.unparse(base) for base in node.bases}
31-
32-
return (
33-
not class_name.startswith("_")
34-
and not any(pattern in class_name for pattern in SKIP_PATTERNS)
35-
and not any(base.endswith("P") for base in base_names if isinstance(base, str))
36-
and any(
37-
base.startswith("_") or any(p in base for p in CONTROLLER_BASE_PATTERNS)
38-
for base in base_names
39-
)
40-
)
4114

4215

4316
def get_controller_classes() -> Set[str]:
44-
classes: Set[str] = set()
45-
for py_file in CONTROLLER_DIR.glob("*.py"):
46-
if py_file.name == "__init__.py":
17+
controller_module = importlib.import_module("shiny.playwright.controller")
18+
19+
res: Set[str] = set()
20+
for x in dir(controller_module):
21+
if x.startswith("_") or x.startswith("@"):
4722
continue
48-
try:
49-
tree = ast.parse(py_file.read_text(encoding="utf-8"))
50-
classes.update(
51-
node.name
52-
for node in ast.walk(tree)
53-
if isinstance(node, ast.ClassDef) and _is_valid_controller_class(node)
54-
)
55-
except Exception as e:
56-
pytest.fail(f"Failed to parse {py_file}: {e}")
57-
return classes
23+
res.add(x)
24+
25+
return res
5826

5927

6028
def get_documented_controllers() -> Set[str]:

0 commit comments

Comments
 (0)