-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest_report.py
60 lines (48 loc) · 1.71 KB
/
test_report.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import io
import pytest
import time
from timebudget import timebudget
def test_default_print_immediate():
stream = io.StringIO()
timebudget._default_recorder.out_stream = stream
assert len(stream.getvalue()) == 0
with timebudget("nothing much"):
time.sleep(0.01)
out = stream.getvalue()
assert len(out) > 0, "Default timebudget didn't print"
assert "much" in out
def test_disable_print_immediate():
stream = io.StringIO()
timebudget._default_recorder.out_stream = stream
assert len(stream.getvalue()) == 0
with timebudget("nothing much", quiet=True):
time.sleep(0.01)
out = stream.getvalue()
assert len(out) == 0, "Failed to disable immediate printing"
def test_disable_print_globally():
stream = io.StringIO()
timebudget._default_recorder.out_stream = stream
timebudget.set_quiet()
assert len(stream.getvalue()) == 0
with timebudget("nothing much"):
time.sleep(0.01)
out = stream.getvalue()
assert len(out) == 0, "Failed to disable immediate printing"
timebudget.set_quiet(False)
def test_ms_formatting():
stream = io.StringIO()
timebudget._default_recorder.out_stream = stream
assert len(stream.getvalue()) == 0
with timebudget("really fast"):
time.sleep(0.001)
out = stream.getvalue()
assert "ms" in out, "Short time output did not get formatted in milliseconds"
def test_sec_formatting():
stream = io.StringIO()
timebudget._default_recorder.out_stream = stream
assert len(stream.getvalue()) == 0
with timebudget("slow"):
time.sleep(1.1)
out = stream.getvalue()
assert "sec" in out, "Long time output did not get formatted in seconds"
assert "ms" not in out