1#!/usr/bin/env python3
2# Copyright (c) 2024 Intel Corporation
3#
4# SPDX-License-Identifier: Apache-2.0
5"""
6Status classes to be used instead of str statuses.
7"""
8from __future__ import annotations
9
10from enum import Enum
11
12from colorama import Fore
13
14
15class TwisterStatus(str, Enum):
16    def __str__(self):
17        return str(self.value)
18
19    @classmethod
20    def _missing_(cls, value):
21        super()._missing_(value)
22        if value is None:
23            return TwisterStatus.NONE
24
25    @staticmethod
26    def get_color(status: TwisterStatus) -> str:
27        status2color = {
28            TwisterStatus.PASS: Fore.GREEN,
29            TwisterStatus.NOTRUN: Fore.CYAN,
30            TwisterStatus.SKIP: Fore.YELLOW,
31            TwisterStatus.FILTER: Fore.YELLOW,
32            TwisterStatus.BLOCK: Fore.YELLOW,
33            TwisterStatus.FAIL: Fore.RED,
34            TwisterStatus.ERROR: Fore.RED,
35            TwisterStatus.STARTED: Fore.MAGENTA,
36            TwisterStatus.NONE: Fore.MAGENTA
37        }
38        return status2color.get(status, Fore.RESET)
39
40    # All statuses below this comment can be used for TestCase
41    BLOCK = 'blocked'
42    STARTED = 'started'
43
44    # All statuses below this comment can be used for TestSuite
45    # All statuses below this comment can be used for TestInstance
46    FILTER = 'filtered'
47    NOTRUN = 'not run'
48
49    # All statuses below this comment can be used for Harness
50    NONE = None
51    ERROR = 'error'
52    FAIL = 'failed'
53    PASS = 'passed'
54    SKIP = 'skipped'
55