Skip to content

check_result

Define check result class.

CheckResult

Represent the result of running a check.

Source code in gatorgrade/output/check_result.py
 6
 7
 8
 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
class CheckResult:  # pylint: disable=too-few-public-methods
    """Represent the result of running a check."""

    def __init__(
        self,
        passed: bool,
        description: str,
        json_info,
        path: str = None,
        diagnostic: str = "No diagnostic message available",
    ):
        """Construct a CheckResult.

        Args:
            passed: The passed or failed status of the check result. If true, indicates that the
                check has passed.
            description: The description to use in output.
            json_info: the overall information to be included in json output
            diagnostic: The message to use in output if the check has failed.
        """
        self.passed = passed
        self.description = description
        self.json_info = json_info
        self.diagnostic = diagnostic
        self.path = path

    def display_result(self, show_diagnostic: bool = False) -> str:
        """Print check's passed or failed status, description, and, optionally, diagnostic message.

        If no diagnostic message is available, then the output will say so.

        Args:
            show_diagnostic: If true, show the diagnostic message if the check has failed.
                Defaults to false.
        """
        icon = "✓" if self.passed else "✕"
        icon_color = "green" if self.passed else "red"
        message = f"[{icon_color}]{icon}[/]  {self.description}"
        if not self.passed and show_diagnostic:
            message += f"\n[yellow]   → {self.diagnostic}"
        return message

    def __str__(self, show_diagnostic: bool = False) -> str:
        """Print check's passed or failed status, description, and, optionally, diagnostic message.

        If no diagnostic message is available, then the output will say so.

        Args:
            show_diagnostic: If true, show the diagnostic message if the check has failed.
                Defaults to false.
        """
        message = self.display_result(show_diagnostic)
        return message

    def print(self, show_diagnostic: bool = False) -> None:
        """Print check's passed or failed status, description, and, optionally, diagnostic message.

        If no diagnostic message is available, then the output will say so.

        Args:
            show_diagnostic: If true, show the diagnostic message if the check has failed.
                Defaults to false.
        """
        message = self.display_result(show_diagnostic)
        rich.print(message)

__init__(passed, description, json_info, path=None, diagnostic='No diagnostic message available')

Construct a CheckResult.

Parameters:

Name Type Description Default
passed bool

The passed or failed status of the check result. If true, indicates that the check has passed.

required
description str

The description to use in output.

required
json_info

the overall information to be included in json output

required
diagnostic str

The message to use in output if the check has failed.

'No diagnostic message available'
Source code in gatorgrade/output/check_result.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def __init__(
    self,
    passed: bool,
    description: str,
    json_info,
    path: str = None,
    diagnostic: str = "No diagnostic message available",
):
    """Construct a CheckResult.

    Args:
        passed: The passed or failed status of the check result. If true, indicates that the
            check has passed.
        description: The description to use in output.
        json_info: the overall information to be included in json output
        diagnostic: The message to use in output if the check has failed.
    """
    self.passed = passed
    self.description = description
    self.json_info = json_info
    self.diagnostic = diagnostic
    self.path = path

__str__(show_diagnostic=False)

Print check's passed or failed status, description, and, optionally, diagnostic message.

If no diagnostic message is available, then the output will say so.

Parameters:

Name Type Description Default
show_diagnostic bool

If true, show the diagnostic message if the check has failed. Defaults to false.

False
Source code in gatorgrade/output/check_result.py
48
49
50
51
52
53
54
55
56
57
58
def __str__(self, show_diagnostic: bool = False) -> str:
    """Print check's passed or failed status, description, and, optionally, diagnostic message.

    If no diagnostic message is available, then the output will say so.

    Args:
        show_diagnostic: If true, show the diagnostic message if the check has failed.
            Defaults to false.
    """
    message = self.display_result(show_diagnostic)
    return message

display_result(show_diagnostic=False)

Print check's passed or failed status, description, and, optionally, diagnostic message.

If no diagnostic message is available, then the output will say so.

Parameters:

Name Type Description Default
show_diagnostic bool

If true, show the diagnostic message if the check has failed. Defaults to false.

False
Source code in gatorgrade/output/check_result.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def display_result(self, show_diagnostic: bool = False) -> str:
    """Print check's passed or failed status, description, and, optionally, diagnostic message.

    If no diagnostic message is available, then the output will say so.

    Args:
        show_diagnostic: If true, show the diagnostic message if the check has failed.
            Defaults to false.
    """
    icon = "✓" if self.passed else "✕"
    icon_color = "green" if self.passed else "red"
    message = f"[{icon_color}]{icon}[/]  {self.description}"
    if not self.passed and show_diagnostic:
        message += f"\n[yellow]   → {self.diagnostic}"
    return message

print(show_diagnostic=False)

Print check's passed or failed status, description, and, optionally, diagnostic message.

If no diagnostic message is available, then the output will say so.

Parameters:

Name Type Description Default
show_diagnostic bool

If true, show the diagnostic message if the check has failed. Defaults to false.

False
Source code in gatorgrade/output/check_result.py
60
61
62
63
64
65
66
67
68
69
70
def print(self, show_diagnostic: bool = False) -> None:
    """Print check's passed or failed status, description, and, optionally, diagnostic message.

    If no diagnostic message is available, then the output will say so.

    Args:
        show_diagnostic: If true, show the diagnostic message if the check has failed.
            Defaults to false.
    """
    message = self.display_result(show_diagnostic)
    rich.print(message)