summaryrefslogtreecommitdiffstats
path: root/python/mozperftest/mozperftest/tests/test_argparser.py
blob: b65a0809f8c78d3fc737de24e2f963bab62ad8e2 (plain)
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/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/.
from datetime import date

import mozunit
import pytest

from mozperftest.argparser import (
    Options,
    PerftestArgumentParser,
    PerftestToolsArgumentParser,
)


def test_argparser():
    parser = PerftestArgumentParser()
    args = ["test_one.js"]
    res = parser.parse_args(args)
    assert res.tests == ["test_one.js"]


def test_argparser_defaults():
    parser = PerftestArgumentParser()
    args = ["test_one.js"]
    res = parser.parse_args(args)
    assert res.console_simplify_exclude == ["statistics"]


def test_options():
    assert Options.args["--proxy"]["help"] == "Activates the proxy layer"
    assert Options.args["--no-browsertime"]["help"] == (
        "Deactivates the " "browsertime layer"
    )


def test_layer_option():
    parser = PerftestArgumentParser()
    assert parser.parse_args(["--notebook-metrics"]) == parser.parse_args(
        ["--notebook-metrics", "--notebook"]
    )
    assert parser.parse_known_args(["--notebook-metrics"]) == parser.parse_known_args(
        ["--notebook-metrics", "--notebook"]
    )


def test_bad_test_date():
    parser = PerftestArgumentParser()
    args = ["test_one.js", "--test-date", "bleh"]
    with pytest.raises(SystemExit):
        parser.parse_args(args)


def test_test_date_today():
    parser = PerftestArgumentParser()
    args = ["test_one.js", "--test-date", "today"]
    res = parser.parse_args(args)
    assert res.test_date == date.today().strftime("%Y.%m.%d")


def test_perfherder_metrics():

    parser = PerftestArgumentParser()
    args = [
        "test_one.js",
        "--perfherder-metrics",
        "name:foo,unit:ms,alertThreshold:2",
        "name:baz,unit:count,alertThreshold:2,lowerIsBetter:false",
    ]

    res = parser.parse_args(args)
    assert res.perfherder_metrics[0]["name"] == "foo"
    assert res.perfherder_metrics[1]["alertThreshold"] == 2

    args = [
        "test_one.js",
        "--perfherder-metrics",
        "name:foo,unit:ms,alertThreshold:2",
        "name:baz,UNKNOWN:count,alertThreshold:2,lowerIsBetter:false",
    ]

    with pytest.raises(SystemExit):
        parser.parse_args(args)

    args = [
        "test_one.js",
        "--perfherder-metrics",
        "name:foo,unit:ms,alertThreshold:2",
        "namemalformedbaz,alertThreshold:2,lowerIsBetter:false",
    ]

    with pytest.raises(SystemExit):
        parser.parse_args(args)

    # missing the name!
    args = [
        "test_one.js",
        "--perfherder-metrics",
        "name:foo,unit:ms,alertThreshold:2",
        "alertThreshold:2,lowerIsBetter:false",
    ]

    with pytest.raises(SystemExit):
        parser.parse_args(args)

    # still supporting just plain names
    args = [
        "test_one.js",
        "--perfherder-metrics",
        "name:foo,unit:euros,alertThreshold:2",
        "baz",
    ]

    res = parser.parse_args(args)
    assert res.perfherder_metrics[1]["name"] == "baz"
    assert res.perfherder_metrics[0]["name"] == "foo"
    assert res.perfherder_metrics[0]["unit"] == "euros"


def test_tools_argparser_bad_tool():
    with pytest.raises(SystemExit):
        PerftestToolsArgumentParser()


def test_tools_bad_argparser():
    PerftestToolsArgumentParser.tool = "side-by-side"
    parser = PerftestToolsArgumentParser()
    args = [
        "-t",
        "browsertime-first-install-firefox-welcome",
        "--base-platform",
        "test-linux1804-64-shippable-qr",
    ]
    with pytest.raises(SystemExit):
        parser.parse_args(args)


def test_tools_argparser():
    PerftestToolsArgumentParser.tool = "side-by-side"
    parser = PerftestToolsArgumentParser()
    args = [
        "-t",
        "browsertime-first-install-firefox-welcome",
        "--base-platform",
        "test-linux1804-64-shippable-qr",
        "--base-revision",
        "438092d03ac4b9c36b52ba455da446afc7e14213",
        "--new-revision",
        "29943068938aa9e94955dbe13c2e4c254553e4ce",
    ]
    res = parser.parse_args(args)
    assert res.test_name == "browsertime-first-install-firefox-welcome"
    assert res.platform == "test-linux1804-64-shippable-qr"
    assert res.base_revision == "438092d03ac4b9c36b52ba455da446afc7e14213"
    assert res.new_revision == "29943068938aa9e94955dbe13c2e4c254553e4ce"


if __name__ == "__main__":
    mozunit.main()