summaryrefslogtreecommitdiffstats
path: root/python/mozperftest/mozperftest/tests/test_ir_schema.py
blob: 41f3ad78048ac366fe8c1a22e9d9547d1e7441e2 (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
#!/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 jsonschema.exceptions import ValidationError

from mozperftest.metrics.utils import validate_intermediate_results


def test_results_with_directory():
    test_result = {"results": "path-to-results", "name": "the-name"}
    validate_intermediate_results(test_result)


def test_results_with_measurements():
    test_result = {
        "results": [
            {"name": "metric-1", "values": [0, 1, 1, 0]},
            {"name": "metric-2", "values": [0, 1, 1, 0]},
        ],
        "name": "the-name",
    }
    validate_intermediate_results(test_result)


def test_results_with_suite_perfherder_options():
    test_result = {
        "results": [
            {"name": "metric-1", "values": [0, 1, 1, 0]},
            {"name": "metric-2", "values": [0, 1, 1, 0]},
        ],
        "name": "the-name",
        "extraOptions": ["an-extra-option"],
        "value": 9000,
    }
    validate_intermediate_results(test_result)


def test_results_with_subtest_perfherder_options():
    test_result = {
        "results": [
            {"name": "metric-1", "shouldAlert": True, "values": [0, 1, 1, 0]},
            {"name": "metric-2", "alertThreshold": 1.0, "values": [0, 1, 1, 0]},
        ],
        "name": "the-name",
        "extraOptions": ["an-extra-option"],
        "value": 9000,
    }
    validate_intermediate_results(test_result)


def test_results_with_bad_suite_property():
    test_result = {
        "results": "path-to-results",
        "name": "the-name",
        "I'll cause a failure,": "an expected failure",
    }
    with pytest.raises(ValidationError):
        validate_intermediate_results(test_result)


def test_results_with_bad_subtest_property():
    test_result = {
        "results": [
            # Error is in "shouldalert", it should be "shouldAlert"
            {"name": "metric-1", "shouldalert": True, "values": [0, 1, 1, 0]},
            {"name": "metric-2", "alertThreshold": 1.0, "values": [0, 1, 1, 0]},
        ],
        "name": "the-name",
        "extraOptions": ["an-extra-option"],
        "value": 9000,
    }
    with pytest.raises(ValidationError):
        validate_intermediate_results(test_result)


def test_results_with_missing_suite_property():
    test_result = {
        # Missing "results"
        "name": "the-name"
    }
    with pytest.raises(ValidationError):
        validate_intermediate_results(test_result)


def test_results_with_missing_subtest_property():
    test_result = {
        "results": [
            # Missing "values"
            {"name": "metric-2", "alertThreshold": 1.0}
        ],
        "name": "the-name",
        "extraOptions": ["an-extra-option"],
        "value": 9000,
    }
    with pytest.raises(ValidationError):
        validate_intermediate_results(test_result)


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