Skip to content

CSV Reporter

CSV Report management for ANTA.

ReportCsv

Build a CSV report.

Headers dataclass

Headers(device: str = 'Device', test_name: str = 'Test Name', test_status: str = 'Test Status', messages: str = 'Message(s)', description: str = 'Test description', categories: str = 'Test category')

Headers for the CSV report.

convert_to_list classmethod

convert_to_list(result: TestResult) -> list[str]

Convert a TestResult into a list of string for creating file content.

Parameters:

Name Type Description Default
result TestResult

A TestResult to convert into list.

required

Returns:

Type Description
list[str]

TestResult converted into a list.

Source code in anta/reporter/csv_reporter.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
@classmethod
def convert_to_list(cls, result: TestResult) -> list[str]:
    """Convert a TestResult into a list of string for creating file content.

    Parameters
    ----------
    result
        A TestResult to convert into list.

    Returns
    -------
    list[str]
        TestResult converted into a list.
    """
    message = cls.split_list_to_txt_list(result.messages) if len(result.messages) > 0 else ""
    categories = cls.split_list_to_txt_list(convert_categories(result.categories)) if len(result.categories) > 0 else "None"
    return [
        str(result.name),
        result.test,
        result.result,
        message,
        result.description,
        categories,
    ]

generate classmethod

generate(results: ResultManager, csv_filename: Path) -> None

Build CSV flle with tests results.

Parameters:

Name Type Description Default
results ResultManager

A ResultManager instance.

required
csv_filename Path

File path where to save CSV data.

required

Raises:

Type Description
OSError

if any is raised while writing the CSV file.

Source code in anta/reporter/csv_reporter.py
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
@classmethod
def generate(cls, results: ResultManager, csv_filename: pathlib.Path) -> None:
    """Build CSV flle with tests results.

    Parameters
    ----------
    results
        A ResultManager instance.
    csv_filename
        File path where to save CSV data.

    Raises
    ------
    OSError
        if any is raised while writing the CSV file.
    """
    cls._write_rows(csv_filename, cls._headers(), cls._iter_rows(results))

split_list_to_txt_list classmethod

split_list_to_txt_list(usr_list: list[str], delimiter: str = ' - ') -> str

Split list to multi-lines string.

Parameters:

Name Type Description Default
usr_list list[str]

List of string to concatenate.

required
delimiter str

A delimiter to use to start string. Defaults to None.

' - '

Returns:

Type Description
str

Multi-lines string.

Source code in anta/reporter/csv_reporter.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
@classmethod
def split_list_to_txt_list(cls, usr_list: list[str], delimiter: str = " - ") -> str:
    """Split list to multi-lines string.

    Parameters
    ----------
    usr_list
        List of string to concatenate.
    delimiter
        A delimiter to use to start string. Defaults to None.

    Returns
    -------
    str
        Multi-lines string.

    """
    return f"{delimiter}".join(f"{line}" for line in usr_list)