zephyr/scripts/pylib/twister/twisterlib/statuses.py
Lukasz Mrugala a20e395174 scripts: Fix twisterlib for ruff - SIM401
This fixes the ruff linting error SIM401,
where if-else construction is used instead
of dict.get().

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2024-11-29 15:29:31 +01:00

54 lines
1.5 KiB
Python

#!/usr/bin/env python3
# Copyright (c) 2024 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
"""
Status classes to be used instead of str statuses.
"""
from __future__ import annotations
from enum import Enum
from colorama import Fore
class TwisterStatus(str, Enum):
def __str__(self):
return str(self.value)
@classmethod
def _missing_(cls, value):
super()._missing_(value)
if value is None:
return TwisterStatus.NONE
@staticmethod
def get_color(status: TwisterStatus) -> str:
status2color = {
TwisterStatus.PASS: Fore.GREEN,
TwisterStatus.NOTRUN: Fore.CYAN,
TwisterStatus.SKIP: Fore.YELLOW,
TwisterStatus.FILTER: Fore.YELLOW,
TwisterStatus.BLOCK: Fore.YELLOW,
TwisterStatus.FAIL: Fore.RED,
TwisterStatus.ERROR: Fore.RED,
TwisterStatus.STARTED: Fore.MAGENTA,
TwisterStatus.NONE: Fore.MAGENTA
}
return status2color.get(status, Fore.RESET)
# All statuses below this comment can be used for TestCase
BLOCK = 'blocked'
STARTED = 'started'
# All statuses below this comment can be used for TestSuite
# All statuses below this comment can be used for TestInstance
FILTER = 'filtered'
NOTRUN = 'not run'
# All statuses below this comment can be used for Harness
NONE = None
ERROR = 'error'
FAIL = 'failed'
PASS = 'passed'
SKIP = 'skipped'