5
5
6
6
from kitsune import KitsunePrinter
7
7
8
- COLORED_LINE_REGEX = re .compile (r"(\x1b\[3[0-7](?:;1)?m)(\w+\..+ +\|\x1b\[0m .*)\n" )
8
+ # longer delay = more reliable tests
9
+ DELAY_SECONDS = 0.5
9
10
10
11
11
12
def test_kitsune_printer_plain (tmpdir ):
@@ -20,16 +21,16 @@ def test_kitsune_printer_plain(tmpdir):
20
21
21
22
printer = KitsunePrinter ([a .strpath , b .strpath ], color = False , stream = buf )
22
23
printer .start ()
23
- time .sleep (0.01 )
24
+ time .sleep (DELAY_SECONDS )
24
25
25
26
a .write ("foo\n " , mode = "a+" )
26
- time .sleep (0.01 )
27
+ time .sleep (DELAY_SECONDS )
27
28
28
29
b .write ("bar\n " , mode = "a+" )
29
- time .sleep (0.01 )
30
+ time .sleep (DELAY_SECONDS )
30
31
31
32
a .write ("baz\n " , mode = "a+" )
32
- time .sleep (0.01 )
33
+ time .sleep (DELAY_SECONDS )
33
34
34
35
output = buf .getvalue ().splitlines ()
35
36
assert len (output ) == 3
@@ -40,7 +41,7 @@ def test_kitsune_printer_plain(tmpdir):
40
41
printer .stop ()
41
42
42
43
a .write ("printer already stopped\n " , mode = "a+" )
43
- time .sleep (0.1 )
44
+ time .sleep (DELAY_SECONDS )
44
45
45
46
output = buf .getvalue ().splitlines ()
46
47
assert len (output ) == 3
@@ -61,19 +62,21 @@ def test_kitsune_printer_rainbow(tmpdir):
61
62
62
63
printer = KitsunePrinter ([a .strpath , b .strpath ], color = True , stream = buf )
63
64
printer .start ()
64
- time .sleep (0.01 )
65
+ time .sleep (DELAY_SECONDS )
65
66
66
67
a .write ("foo\n " , mode = "a+" )
67
- time .sleep (0.01 )
68
+ time .sleep (DELAY_SECONDS )
68
69
69
70
b .write ("bar\n " , mode = "a+" )
70
- time .sleep (0.01 )
71
+ time .sleep (DELAY_SECONDS )
71
72
72
73
a .write ("baz\n " , mode = "a+" )
73
- time .sleep (0.01 )
74
+ time .sleep (DELAY_SECONDS )
75
+
76
+ colored_line_regex = re .compile (r"(\x1b\[3[0-7](?:;1)?m)(\w+\..+ +\|\x1b\[0m .*)\n" )
74
77
75
78
value = buf .getvalue ()
76
- matches = COLORED_LINE_REGEX .findall (value )
79
+ matches = colored_line_regex .findall (value )
77
80
assert len (matches ) == 3
78
81
output = tuple (zip (* matches ))[1 ]
79
82
assert output [0 ] == "a.log |\033 [0m foo"
@@ -83,9 +86,10 @@ def test_kitsune_printer_rainbow(tmpdir):
83
86
printer .stop ()
84
87
85
88
a .write ("printer already stopped\n " , mode = "a+" )
86
- time .sleep (0.1 )
89
+ time .sleep (DELAY_SECONDS )
87
90
88
- matches = COLORED_LINE_REGEX .findall (buf .getvalue ())
91
+ value = buf .getvalue ()
92
+ matches = colored_line_regex .findall (value )
89
93
assert len (matches ) == 3
90
94
output = tuple (zip (* matches ))[1 ]
91
95
assert output [0 ] == "a.log |\033 [0m foo"
0 commit comments