Skip to content

Jinja Reporter

Deprecated import

ReportJinja has been moved. Import it from anta.reporter.jinja_reporter. Direct import from anta.reporter will be removed in ANTA v2.0.0.

ReportJinja

ReportJinja(template_path: Path)

Report builder based on a Jinja2 template.

render

render(data: list[dict[str, Any]], *, trim_blocks: bool = True, lstrip_blocks: bool = True) -> str

Build a report based on a Jinja2 template.

Report is built based on a J2 template provided by user. Data structure sent to template is:

Example
>>> print(ResultManager.json)
[
    {
        name: ...,
        test: ...,
        result: ...,
        messages: [...]
        categories: ...,
        description: ...,
    }
]

Parameters:

Name Type Description Default
data list[dict[str, Any]]

List of results from ResultManager.results.

required
trim_blocks bool

enable trim_blocks for J2 rendering.

True
lstrip_blocks bool

enable lstrip_blocks for J2 rendering.

True

Returns:

Type Description
str

Rendered template

Source code in anta/reporter/jinja_reporter.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
def render(self, data: list[dict[str, Any]], *, trim_blocks: bool = True, lstrip_blocks: bool = True) -> str:
    """Build a report based on a Jinja2 template.

    Report is built based on a J2 template provided by user.
    Data structure sent to template is:

    Example
    -------
    ```
    >>> print(ResultManager.json)
    [
        {
            name: ...,
            test: ...,
            result: ...,
            messages: [...]
            categories: ...,
            description: ...,
        }
    ]
    ```

    Parameters
    ----------
    data
        List of results from `ResultManager.results`.
    trim_blocks
        enable trim_blocks for J2 rendering.
    lstrip_blocks
        enable lstrip_blocks for J2 rendering.

    Returns
    -------
    str
        Rendered template

    """
    with self.template_path.open(encoding="utf-8") as file_:
        template = Template(file_.read(), trim_blocks=trim_blocks, lstrip_blocks=lstrip_blocks)

    return template.render({"data": data})