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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import mozunit
import pytest
from mozperftest.script import (
BadOptionTypeError,
MissingFieldError,
ParseError,
ScriptInfo,
ScriptType,
)
from mozperftest.tests.support import (
EXAMPLE_MOCHITEST_TEST,
EXAMPLE_MOCHITEST_TEST2,
EXAMPLE_TEST,
EXAMPLE_XPCSHELL_TEST,
EXAMPLE_XPCSHELL_TEST2,
HERE,
temp_file,
)
def check_options(info):
assert info["options"]["default"]["perfherder"]
assert info["options"]["linux"]["perfherder_metrics"] == [
{"name": "speed", "unit": "bps_lin"}
]
assert info["options"]["win"]["perfherder_metrics"] == [
{"name": "speed", "unit": "bps_win"}
]
assert info["options"]["mac"]["perfherder_metrics"] == [
{"name": "speed", "unit": "bps_mac"}
]
def test_scriptinfo_bt():
info = ScriptInfo(EXAMPLE_TEST)
assert info["author"] == "N/A"
display = str(info)
assert "The description of the example test." in display
assert info.script_type == ScriptType.browsertime
check_options(info)
@pytest.mark.parametrize("script", [EXAMPLE_MOCHITEST_TEST, EXAMPLE_MOCHITEST_TEST2])
def test_scriptinfo_mochitest(script):
info = ScriptInfo(script)
assert info["author"] == "N/A"
display = str(info)
assert "N/A" in display
assert "Performance Team" in display
assert "Test test" in display
assert info.script_type == ScriptType.mochitest
assert info["options"]["default"]["manifest"] == "mochitest-common.ini"
assert info["options"]["default"]["manifest_flavor"] == "plain"
assert info["options"]["default"]["perfherder_metrics"] == [
{"name": "Registration", "unit": "ms"}
]
def test_scriptinfo_mochitest_missing_perfmetadata():
with temp_file(name="sample.html", content="<html></html>") as temp:
with pytest.raises(ParseError) as exc_info:
ScriptInfo(temp)
assert "MissingPerfMetadata" in str(exc_info.value)
@pytest.mark.parametrize("script", [EXAMPLE_XPCSHELL_TEST, EXAMPLE_XPCSHELL_TEST2])
def test_scriptinfo_xpcshell(script):
info = ScriptInfo(script)
assert info["author"] == "N/A"
display = str(info)
assert "The description of the example test." in display
assert info.script_type == ScriptType.xpcshell
check_options(info)
def test_scriptinfo_failure():
bad_example = HERE / "data" / "failing-samples" / "perftest_doc_failure_example.js"
with pytest.raises(MissingFieldError):
ScriptInfo(bad_example)
def test_parserror():
exc = Exception("original")
error = ParseError("script", exc)
assert error.exception is exc
assert "original" in str(error)
def test_update_args():
args = {"perfherder_metrics": [{"name": "yey"}]}
info = ScriptInfo(EXAMPLE_TEST)
new_args = info.update_args(**args)
# arguments should not be overriden
assert new_args["perfherder_metrics"] == [{"name": "yey"}]
# arguments in platform-specific options should
# override default options
assert new_args["verbose"]
def test_update_args_metrics_list_failure():
args = {"perfherder_metrics": "yey"}
info = ScriptInfo(EXAMPLE_TEST)
with pytest.raises(BadOptionTypeError):
info.update_args(**args)
def test_update_args_metrics_json_failure():
args = {"perfherder_metrics": ["yey"]}
info = ScriptInfo(EXAMPLE_TEST)
with pytest.raises(BadOptionTypeError):
info.update_args(**args)
if __name__ == "__main__":
mozunit.main()
|