Skip to content

Commit 92263d5

Browse files
committed
Made tests more reliable
1 parent 786b931 commit 92263d5

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

kitsune/__main__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
def parse_args(args=None):
1313
p = argparse.ArgumentParser(
14-
prog='kitsune',
14+
prog="kitsune",
1515
description="A prettier way to tail multiple files.",
1616
add_help=False,
1717
)

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def run(self):
6767
author=__author__,
6868
author_email=__email__,
6969
url=__url__,
70-
packages=['kitsune'],
70+
packages=["kitsune"],
7171
license=__license__,
7272
classifiers=[
7373
"Development Status :: 3 - Alpha",

tests/test_kitsune.py

+17-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
from kitsune import KitsunePrinter
77

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
910

1011

1112
def test_kitsune_printer_plain(tmpdir):
@@ -20,16 +21,16 @@ def test_kitsune_printer_plain(tmpdir):
2021

2122
printer = KitsunePrinter([a.strpath, b.strpath], color=False, stream=buf)
2223
printer.start()
23-
time.sleep(0.01)
24+
time.sleep(DELAY_SECONDS)
2425

2526
a.write("foo\n", mode="a+")
26-
time.sleep(0.01)
27+
time.sleep(DELAY_SECONDS)
2728

2829
b.write("bar\n", mode="a+")
29-
time.sleep(0.01)
30+
time.sleep(DELAY_SECONDS)
3031

3132
a.write("baz\n", mode="a+")
32-
time.sleep(0.01)
33+
time.sleep(DELAY_SECONDS)
3334

3435
output = buf.getvalue().splitlines()
3536
assert len(output) == 3
@@ -40,7 +41,7 @@ def test_kitsune_printer_plain(tmpdir):
4041
printer.stop()
4142

4243
a.write("printer already stopped\n", mode="a+")
43-
time.sleep(0.1)
44+
time.sleep(DELAY_SECONDS)
4445

4546
output = buf.getvalue().splitlines()
4647
assert len(output) == 3
@@ -61,19 +62,21 @@ def test_kitsune_printer_rainbow(tmpdir):
6162

6263
printer = KitsunePrinter([a.strpath, b.strpath], color=True, stream=buf)
6364
printer.start()
64-
time.sleep(0.01)
65+
time.sleep(DELAY_SECONDS)
6566

6667
a.write("foo\n", mode="a+")
67-
time.sleep(0.01)
68+
time.sleep(DELAY_SECONDS)
6869

6970
b.write("bar\n", mode="a+")
70-
time.sleep(0.01)
71+
time.sleep(DELAY_SECONDS)
7172

7273
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")
7477

7578
value = buf.getvalue()
76-
matches = COLORED_LINE_REGEX.findall(value)
79+
matches = colored_line_regex.findall(value)
7780
assert len(matches) == 3
7881
output = tuple(zip(*matches))[1]
7982
assert output[0] == "a.log |\033[0m foo"
@@ -83,9 +86,10 @@ def test_kitsune_printer_rainbow(tmpdir):
8386
printer.stop()
8487

8588
a.write("printer already stopped\n", mode="a+")
86-
time.sleep(0.1)
89+
time.sleep(DELAY_SECONDS)
8790

88-
matches = COLORED_LINE_REGEX.findall(buf.getvalue())
91+
value = buf.getvalue()
92+
matches = colored_line_regex.findall(value)
8993
assert len(matches) == 3
9094
output = tuple(zip(*matches))[1]
9195
assert output[0] == "a.log |\033[0m foo"

0 commit comments

Comments
 (0)