frameworks.py¶
clew/wiki/frameworks.py
Standard test structures: which indexed functions are tests, and under what names.
__call__
tuple[str, tuple[str, ...]] | None clew.wiki.frameworks.TestRecognizer.__call__(self, str name, str args, str path)
A function's test identity, if it is a test.
Source · 15 lines
def __call__(self, name: str, args: str, path: str) -> tuple[str, tuple[str, ...]] | None:
"""@brief Recognise. @return Identity or None."""
in_test = (
(path in self.test_files)
if self.test_files is not None
else bool(_TEST_PATH.search(path or ""))
)
if not in_test:
return None
reader = self.macros.get(name)
if reader is not None:
return reader(args or "")
return (name, (name,)) if name.lower().startswith(self.prefixes) else None
Activity · 7 steps
Requirements
for_conn
TestRecognizer clew.wiki.frameworks.TestRecognizer.for_conn(cls, Any conn)
The recogniser for an open index, built once per connection.
Source · 15 lines
def for_conn(cls, conn: Any) -> TestRecognizer:
"""IDENTITY-CHECKED CACHE: a connection supports no weak reference, and a wiki build asks
on every step of a caller walk, so the last few are held and matched by identity.
@brief Build or reuse.
@return The recogniser.
"""
for held, recogniser in _HELD:
if held is conn:
return recogniser
made = cls(_test_files(conn), *_declared_shapes(conn))
_HELD.insert(0, (conn, made))
del _HELD[4:]
return made
Activity · 7 steps
Requirements
recognise_test
tuple[str, tuple[str, ...]] | None clew.wiki.frameworks.recognise_test(str name, str args, str path)
A function's test identity, if it is a test.
Called by none
Tested by
Calls none
Source · 9 lines
def recognise_test(name: str, args: str, path: str) -> tuple[str, tuple[str, ...]] | None:
"""THE PATH-ONLY FORM, for a caller with no index. Against an index, use
`TestRecognizer.for_conn`, which reads test code from `test_scope` and the declared shapes.
@brief Recognise. @return Identity or None.
"""
return TestRecognizer(None, _MACROS, _FUNCTION_PREFIXES)(name, args, path)