summaryrefslogtreecommitdiffstats
path: root/python/mozperftest/mozperftest/tests/test_ir_schema.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /python/mozperftest/mozperftest/tests/test_ir_schema.py
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'python/mozperftest/mozperftest/tests/test_ir_schema.py')
-rw-r--r--python/mozperftest/mozperftest/tests/test_ir_schema.py103
1 files changed, 103 insertions, 0 deletions
diff --git a/python/mozperftest/mozperftest/tests/test_ir_schema.py b/python/mozperftest/mozperftest/tests/test_ir_schema.py
new file mode 100644
index 0000000000..41f3ad7804
--- /dev/null
+++ b/python/mozperftest/mozperftest/tests/test_ir_schema.py
@@ -0,0 +1,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()