|
1 | 1 | from .. import stability
|
| 2 | +from collections import OrderedDict, defaultdict |
2 | 3 |
|
3 | 4 | def test_is_inconsistent():
|
4 | 5 | assert stability.is_inconsistent({"PASS": 10}, 10) is False
|
@@ -65,3 +66,54 @@ def test_get_steps():
|
65 | 66 | assert steps[0][0] == "Running tests in a loop %d times" % repeat_loop
|
66 | 67 | assert steps[1][0] == (
|
67 | 68 | "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