6
6
import time
7
7
from collections import OrderedDict
8
8
from types import TracebackType
9
- from typing import IO , Dict , List , Optional , Sequence , Type , TypeVar
9
+ from typing import IO , Dict , List , NamedTuple , Optional , Sequence , Type , TypeVar
10
10
11
11
from colorama import Fore
12
12
@@ -34,11 +34,19 @@ def _file_support_encoding(chars: Sequence[str], file: IO[str]) -> bool:
34
34
MISS_DURATION = 0.01
35
35
36
36
37
+ class Outcome (NamedTuple ):
38
+ ok : str
39
+ fail : str
40
+ skip : str
41
+
42
+
37
43
class Spinner :
38
44
CLEAR_LINE = "\033 [K"
39
45
max_width = 120
40
46
UNICODE_FRAMES = ["⠋" , "⠙" , "⠹" , "⠸" , "⠼" , "⠴" , "⠦" , "⠧" , "⠇" , "⠏" ]
41
47
ASCII_FRAMES = ["|" , "-" , "+" , "x" , "*" ]
48
+ UNICODE_OUTCOME = Outcome (ok = "✔" , fail = "✖" , skip = "⚠" )
49
+ ASCII_OUTCOME = Outcome (ok = "+" , fail = "!" , skip = "?" )
42
50
43
51
def __init__ (
44
52
self ,
@@ -53,6 +61,9 @@ def __init__(
53
61
self .enabled = enabled
54
62
stream = sys .stdout if stream is None else stream
55
63
self .frames = self .UNICODE_FRAMES if _file_support_encoding (self .UNICODE_FRAMES , stream ) else self .ASCII_FRAMES
64
+ self .outcome = (
65
+ self .UNICODE_OUTCOME if _file_support_encoding (self .UNICODE_OUTCOME , stream ) else self .ASCII_OUTCOME
66
+ )
56
67
self .stream = stream
57
68
self .total = total
58
69
self .print_report = True
@@ -117,13 +128,13 @@ def add(self, name: str) -> None:
117
128
self ._envs [name ] = time .monotonic ()
118
129
119
130
def succeed (self , key : str ) -> None :
120
- self .finalize (key , "OK ✔ " , Fore .GREEN )
131
+ self .finalize (key , f "OK { self . outcome . ok } " , Fore .GREEN )
121
132
122
133
def fail (self , key : str ) -> None :
123
- self .finalize (key , "FAIL ✖ " , Fore .RED )
134
+ self .finalize (key , f "FAIL { self . outcome . fail } " , Fore .RED )
124
135
125
136
def skip (self , key : str ) -> None :
126
- self .finalize (key , "SKIP ⚠ " , Fore .YELLOW )
137
+ self .finalize (key , f "SKIP { self . outcome . skip } " , Fore .YELLOW )
127
138
128
139
def finalize (self , key : str , status : str , color : int ) -> None :
129
140
start_at = self ._envs .pop (key , None )
0 commit comments