Skip to content

Report Manager models

ColorManager Entry

Bases: BaseModel

Color mangement for status report.

Attributes:

Name Type Description
level str

Test result value.

color str

Associated color.

Source code in anta/reporter/models.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
class ColorManager(BaseModel):
    """Color mangement for status report.

    Attributes:
        level (str): Test result value.
        color (str): Associated color.
    """
    level: str
    color: str

    @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

    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)

    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}'

name_must_be_in(v)

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
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
@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()

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
48
49
50
51
52
53
54
55
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()

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
39
40
41
42
43
44
45
46
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: April 6, 2023