catch2.py

clew/catch2.py

Catch2 test cases as covering tests: their titles, tags and `@req` comments (2.1, clew#74).

cases_in

list[Catch2Case] clew.catch2.cases_in(list[str] lines)

Every Catch2 case in a file.

clew/catch2.py:95

Show on the map →

Called by _file_tests

Calls read_case

Source · 6 lines
def cases_in(lines: list[str]) -> list[Catch2Case]:
    """@brief All cases. @return Cases."""
    found = (read_case(lines, n) for n, text in enumerate(lines, 1) if _OPENS.match(text))
    return [c for c in found if c is not None]

Activity · 2 steps
lines 97–97found = (read_case(lines, n) for n, text in enumerate(lines, 1) if _OPENS.match(text))lines 98–98return [c for c in found if c is not None]

Requirements

REQ-DDB-GUARD-010

read_case

Catch2Case | None clew.catch2.read_case(list[str] lines, int line)

The Catch2 case whose macro opens on a given line, if one does.

clew/catch2.py:67

Source · 23 lines
def read_case(lines: list[str], line: int) -> Catch2Case | None:
    """The arguments may span lines (a title on one, tags on the next), so the text is read up to
    the macro's closing parenthesis or `_MAX_ARG_LINES`, whichever comes first.

    @brief Read one case.
    @return Case or None.
    """
    if not 1 <= line <= len(lines) or not _OPENS.match(lines[line - 1]):
        return None
    args = _arguments(lines[line - 1 : line - 1 + _MAX_ARG_LINES])
    literals = _STRING.findall(args)
    title = literals[0] if literals else ""
    tags = tuple(_TAG.findall(literals[1])) if len(literals) > 1 else ()
    block = _comment_block(lines, line)
    return Catch2Case(
        title=title,
        tags=tags,
        reqs=tuple(m for text in block for m in _REQ.findall(text)),
        line=line,
        fails_when=tuple(fails_when_ids("\n".join(block))),
    )

Activity · 8 steps
lines 74–74◇ if not 1 <= line <= len(lines) or not _OPENS.match(lines[line - 1])lines 75–75return Nonelines 76–76args = _arguments(lines[line - 1 : line - 1 + _MAX_ARG_LINES])lines 77–77literals = _STRING.findall(args)lines 78–78title = literals[0] if literals else ""lines 79–79tags = tuple(_TAG.findall(literals[1])) if len(literals) > 1 else ()lines 80–80block = _comment_block(lines, line)lines 81–87return Catch2Case( title=title, tags=tags, reqs=tuple(m for text in block for m in _REQ.findall(text)), line=line, fails_when=tuple(fails_when_ids("\n".join(block))), )

Requirements

REQ-DDB-SCHEMA-006