aboutsummaryrefslogtreecommitdiff
path: root/verif/tests/test_schemavalidation.py
blob: 664e3a42aa4100cf210c80ab889e07158a2d07e6 (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
"""Tests for schemavalidation.py."""
# Copyright (c) 2023, ARM Limited.
# SPDX-License-Identifier: Apache-2.0
import pytest
import schemavalidation.schemavalidation as sch
from jsonschema.exceptions import ValidationError


def test_schemavalidation_full_fail():
    json = {}

    sv = sch.TestDescSchemaValidator()
    with pytest.raises(ValidationError) as excinfo:
        sv.validate_config(json)
    info = str(excinfo.value).split("\n")
    assert info[0] == "'tosa_file' is a required property"


def test_schemavalidation_compliance_fail():
    json = {"version": "v"}

    sv = sch.TestDescSchemaValidator()
    with pytest.raises(ValidationError) as excinfo:
        sv.validate_config(json, sch.TD_SCHEMA_COMPLIANCE)
    info = str(excinfo.value).split("\n")
    assert info[0] == "'tensors' is a required property"


def test_schemavalidation_data_gen_fail():
    json = {"version": "v", "tensors": {"input": {}}}

    sv = sch.TestDescSchemaValidator()
    with pytest.raises(ValidationError) as excinfo:
        sv.validate_config(json, sch.TD_SCHEMA_DATA_GEN)
    info = str(excinfo.value).split("\n")
    assert info[0] == "'generator' is a required property"


def test_schemavalidation_full_minimal():
    json = {
        "tosa_file": "file",
        "ifm_name": ["name1", "name2"],
        "ifm_file": ["file1", "file2"],
        "ofm_name": ["name1", "name2"],
        "ofm_file": ["file1", "file2"],
    }

    sv = sch.TestDescSchemaValidator()
    sv.validate_config(json)


def test_schemavalidation_full_unexpected():
    json = {
        "tosa_file": "file",
        "ifm_name": ["name1", "name2"],
        "ifm_file": ["file1", "file2"],
        "ofm_name": ["name1", "name2"],
        "ofm_file": ["file1", "file2"],
        "unexpected_property": 1,
    }

    sv = sch.TestDescSchemaValidator()
    with pytest.raises(ValidationError) as excinfo:
        sv.validate_config(json)
    info = str(excinfo.value).split("\n")
    assert (
        info[0]
        == "Additional properties are not allowed ('unexpected_property' was unexpected)"
    )


def test_schemavalidation_compliance_minimal():
    json = {
        "version": "v",
        "tensors": {"output": {"mode": "mode", "data_type": "type"}},
    }

    sv = sch.TestDescSchemaValidator()
    sv.validate_config(json, sch.TD_SCHEMA_COMPLIANCE)


def test_schemavalidation_data_gen_minimal():
    json = {
        "version": "v",
        "tensors": {
            "input": {
                "generator": "generator",
                "data_type": "type",
                "input_type": "constant",
                "shape": [],
                "op": "name",
                "input_pos": 0,
            }
        },
    }

    sv = sch.TestDescSchemaValidator()
    sv.validate_config(json, sch.TD_SCHEMA_DATA_GEN)