blob: 664e3a42aa4100cf210c80ab889e07158a2d07e6 [file] [log] [blame]
Jeremy Johnson77fc6142023-09-04 17:04:21 +01001"""Tests for schemavalidation.py."""
2# Copyright (c) 2023, ARM Limited.
3# SPDX-License-Identifier: Apache-2.0
4import pytest
5import schemavalidation.schemavalidation as sch
6from jsonschema.exceptions import ValidationError
7
8
9def test_schemavalidation_full_fail():
10 json = {}
11
12 sv = sch.TestDescSchemaValidator()
13 with pytest.raises(ValidationError) as excinfo:
14 sv.validate_config(json)
15 info = str(excinfo.value).split("\n")
16 assert info[0] == "'tosa_file' is a required property"
17
18
19def test_schemavalidation_compliance_fail():
20 json = {"version": "v"}
21
22 sv = sch.TestDescSchemaValidator()
23 with pytest.raises(ValidationError) as excinfo:
24 sv.validate_config(json, sch.TD_SCHEMA_COMPLIANCE)
25 info = str(excinfo.value).split("\n")
26 assert info[0] == "'tensors' is a required property"
27
28
29def test_schemavalidation_data_gen_fail():
30 json = {"version": "v", "tensors": {"input": {}}}
31
32 sv = sch.TestDescSchemaValidator()
33 with pytest.raises(ValidationError) as excinfo:
34 sv.validate_config(json, sch.TD_SCHEMA_DATA_GEN)
35 info = str(excinfo.value).split("\n")
36 assert info[0] == "'generator' is a required property"
37
38
39def test_schemavalidation_full_minimal():
40 json = {
41 "tosa_file": "file",
42 "ifm_name": ["name1", "name2"],
43 "ifm_file": ["file1", "file2"],
44 "ofm_name": ["name1", "name2"],
45 "ofm_file": ["file1", "file2"],
46 }
47
48 sv = sch.TestDescSchemaValidator()
49 sv.validate_config(json)
50
51
52def test_schemavalidation_full_unexpected():
53 json = {
54 "tosa_file": "file",
55 "ifm_name": ["name1", "name2"],
56 "ifm_file": ["file1", "file2"],
57 "ofm_name": ["name1", "name2"],
58 "ofm_file": ["file1", "file2"],
59 "unexpected_property": 1,
60 }
61
62 sv = sch.TestDescSchemaValidator()
63 with pytest.raises(ValidationError) as excinfo:
64 sv.validate_config(json)
65 info = str(excinfo.value).split("\n")
66 assert (
67 info[0]
68 == "Additional properties are not allowed ('unexpected_property' was unexpected)"
69 )
70
71
72def test_schemavalidation_compliance_minimal():
73 json = {
74 "version": "v",
Jeremy Johnsonbb0935f2023-09-14 16:43:48 +010075 "tensors": {"output": {"mode": "mode", "data_type": "type"}},
Jeremy Johnson77fc6142023-09-04 17:04:21 +010076 }
77
78 sv = sch.TestDescSchemaValidator()
79 sv.validate_config(json, sch.TD_SCHEMA_COMPLIANCE)
80
81
82def test_schemavalidation_data_gen_minimal():
83 json = {
84 "version": "v",
85 "tensors": {
86 "input": {
87 "generator": "generator",
88 "data_type": "type",
89 "input_type": "constant",
90 "shape": [],
91 "op": "name",
92 "input_pos": 0,
93 }
94 },
95 }
96
97 sv = sch.TestDescSchemaValidator()
98 sv.validate_config(json, sch.TD_SCHEMA_DATA_GEN)