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
|
#!/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_TEST,
EXAMPLE_XPCSHELL_TEST,
EXAMPLE_XPCSHELL_TEST2,
HERE,
)
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_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()
|