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.
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
Requirements
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.
Called by _link_catch2_cases, cases_in, import_test_failure_modes
Tested by
Calls _arguments, _comment_block, fails_when_ids
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))),
)