Skip to content

Commit 75574c8

Browse files
svillarmoz-wptsync-bot
authored andcommitted
Bug 1626293 [wpt PR 22568] - Unit test for LogHandler, a=testonly
Automatic update from web-platform-tests Unit test for LogHandler (#22568) The LogHandler is the class that handles updating test and subtest status in log. This test increases the overall code coverage of stability.py a 12%. -- wpt-commits: b93f582ae4903d7af5e002d390596ae369b81ea8 wpt-pr: 22568
1 parent df2b89c commit 75574c8

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_stability.py

+52
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from .. import stability
2+
from collections import OrderedDict, defaultdict
23

34
def test_is_inconsistent():
45
assert stability.is_inconsistent({"PASS": 10}, 10) is False
@@ -65,3 +66,54 @@ def test_get_steps():
6566
assert steps[0][0] == "Running tests in a loop %d times" % repeat_loop
6667
assert steps[1][0] == (
6768
"Running tests in a loop with restarts %d times" % repeat_restart)
69+
70+
71+
def test_log_handler():
72+
handler = stability.LogHandler()
73+
data = OrderedDict()
74+
data["test"] = "test_name"
75+
test = handler.find_or_create_test(data)
76+
assert test["subtests"] == OrderedDict()
77+
assert test["status"] == defaultdict(int)
78+
assert test["longest_duration"] == defaultdict(float)
79+
assert test == handler.find_or_create_test(data)
80+
81+
start_time = 100
82+
data["time"] = start_time
83+
handler.test_start(data)
84+
assert test["start_time"] == start_time
85+
86+
data["subtest"] = "subtest_name"
87+
subtest = handler.find_or_create_subtest(data)
88+
assert subtest["status"] == defaultdict(int)
89+
assert subtest["messages"] == set()
90+
assert subtest == handler.find_or_create_subtest(data)
91+
92+
data["status"] = 0
93+
assert subtest["status"][data["status"]] == 0
94+
handler.test_status(data)
95+
assert subtest["status"][data["status"]] == 1
96+
handler.test_status(data)
97+
assert subtest["status"][data["status"]] == 2
98+
data["status"] = 1
99+
assert subtest["status"][data["status"]] == 0
100+
message = "test message"
101+
data["message"] = message
102+
handler.test_status(data)
103+
assert subtest["status"][data["status"]] == 1
104+
assert len(subtest["messages"]) == 1
105+
assert message in subtest["messages"]
106+
107+
test_duration = 10
108+
data["time"] = data["time"] + test_duration
109+
handler.test_end(data)
110+
assert test["longest_duration"][data["status"]] == test_duration
111+
assert "timeout" not in test
112+
113+
data["test2"] = "test_name_2"
114+
timeout = 5
115+
data["extra"] = {}
116+
data["extra"]["test_timeout"] = timeout
117+
handler.test_start(data)
118+
handler.test_end(data)
119+
assert test["timeout"] == timeout * 1000

0 commit comments

Comments
 (0)