Skip to content

Report Manager models

ColorManager

Bases: BaseModel

Color management for status report.

Attributes:

Name Type Description
level str

Test result value.

color str

Associated color.

name_must_be_in

name_must_be_in(v: str) -> str

Status validator

Validate status is a supported one

Parameters:

Name Type Description Default
v str

User defined level

required

Raises:

Type Description
ValueError

If level is unsupported

Returns:

Name Type Description
str str

level value

Source code in anta/reporter/models.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@validator("level", allow_reuse=True)
def name_must_be_in(cls, v: str) -> str:
    """
    Status validator

    Validate status is a supported one

    Args:
        v (str): User defined level

    Raises:
        ValueError: If level is unsupported

    Returns:
        str: level value
    """
    if v not in RESULT_OPTIONS:
        raise ValueError(f"must be one of {RESULT_OPTIONS}")
    return v

string

string() -> str

Build an str with color code

Returns:

Name Type Description
str str

String with level and its associated color

Source code in anta/reporter/models.py
49
50
51
52
53
54
55
56
def string(self) -> str:
    """
    Build an str with color code

    Returns:
        str: String with level and its associated color
    """
    return f"[{self.color}]{self.level}"

style_rich

style_rich() -> Text

Build a rich Text syntax with color

Returns:

Name Type Description
Text Text

object with level string and its associated color.

Source code in anta/reporter/models.py
40
41
42
43
44
45
46
47
def style_rich(self) -> Text:
    """
    Build a rich Text syntax with color

    Returns:
        Text: object with level string and its associated color.
    """
    return Text(self.level, style=self.color)

Last update: July 19, 2023