forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add json validate (openvinotoolkit#6449)
* Add json validate * Fix json schema * Fix schema loader * Add unit test * Update bom file * Update all requarments * Update dev requarments * Update requrments * Update path to schema * Update schema * Add some unit tests * Move schema to root dir * Update schema path in bom file * Fix unit test * Fix bom * Change path to schema * update setup * Fix setup * Fix mo args test * Refactoring some code * Refactoring according to review * Update sort imports * Remove id attribute from schema * Refactoring validator * Fix according to review * Move schema from json to dict. Update unit tests. * Fix BOM file * Update bom file
- Loading branch information
Showing
13 changed files
with
204 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# Copyright (C) 2018-2021 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
schema_dict = { | ||
"definitions": {}, | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "Root", | ||
"type": "array", | ||
"default": [], | ||
"items": { | ||
"$id": "#root/items", | ||
"title": "Items", | ||
"type": "object", | ||
"required": [ | ||
"id", | ||
"match_kind" | ||
], | ||
"properties": { | ||
"custom_attributes": { | ||
"$id": "#root/items/custom_attributes", | ||
"title": "Custom_attributes", | ||
"type": "object", | ||
"properties": { | ||
} | ||
}, | ||
"id": { | ||
"$id": "#root/items/id", | ||
"title": "Id", | ||
"type": "string", | ||
"pattern": "^.*$", | ||
"minLength": 1 | ||
}, | ||
"inputs": { | ||
"$id": "#root/items/inputs", | ||
"title": "Inputs", | ||
"type": "array", | ||
"default": [], | ||
"items": { | ||
"$id": "#root/items/inputs/items", | ||
"title": "Items", | ||
"type": "array", | ||
"default": [], | ||
"items": { | ||
"$id": "#root/items/inputs/items/items", | ||
"title": "Items", | ||
"type": "object", | ||
"properties": { | ||
"node": { | ||
"$id": "#root/items/inputs/items/items/node", | ||
"title": "Node", | ||
"type": "string", | ||
"default": "", | ||
"pattern": "^.*$" | ||
}, | ||
"port": { | ||
"$id": "#root/items/inputs/items/items/port", | ||
"title": "Port", | ||
"type": "integer", | ||
"default": 0 | ||
} | ||
}, | ||
"required": ["node", "port"] | ||
} | ||
|
||
} | ||
}, | ||
"instances": { | ||
"$id": "#root/items/instances", | ||
"title": "Instances", | ||
"type": ["array", "object"], | ||
"items": { | ||
"$id": "#root/items/instances/items", | ||
"title": "Items", | ||
"type": "string", | ||
"default": "", | ||
"pattern": "^.*$" | ||
} | ||
}, | ||
"match_kind": { | ||
"$id": "#root/items/match_kind", | ||
"title": "Match_kind", | ||
"type": "string", | ||
"enum": ["points", "scope", "general"], | ||
"default": "points", | ||
"pattern": "^.*$" | ||
}, | ||
"outputs": { | ||
"$id": "#root/items/outputs", | ||
"title": "Outputs", | ||
"type": "array", | ||
"default": [], | ||
"items": { | ||
"$id": "#root/items/outputs/items", | ||
"title": "Items", | ||
"type": "object", | ||
"properties": { | ||
"node": { | ||
"$id": "#root/items/outputs/items/node", | ||
"title": "Node", | ||
"type": "string", | ||
"default": "", | ||
"pattern": "^.*$" | ||
}, | ||
"port": { | ||
"$id": "#root/items/outputs/items/port", | ||
"title": "Port", | ||
"type": "integer", | ||
"default": 0 | ||
} | ||
}, | ||
"required": ["node", "port"] | ||
} | ||
|
||
}, | ||
"include_inputs_to_sub_graph": { | ||
"$id": "#root/items/include_inputs_to_sub_graph", | ||
"title": "Include_inputs_to_sub_graph", | ||
"type": "boolean", | ||
"default": False | ||
}, | ||
"include_outputs_to_sub_graph": { | ||
"$id": "#root/items/include_outputs_to_sub_graph", | ||
"title": "Include_outputs_to_sub_graph", | ||
"type": "boolean", | ||
"default": False | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ onnx>=1.8.1 | |
defusedxml>=0.7.1 | ||
urllib3>=1.26.4 | ||
requests>=2.25.1 | ||
fastjsonschema~=2.15.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ numpy>=1.16.6,<1.20 | |
protobuf>=3.15.6 | ||
defusedxml>=0.7.1 | ||
requests>=2.25.1 | ||
fastjsonschema~=2.15.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ test-generator==0.1.1 | |
defusedxml>=0.5.0 | ||
requests>=2.20.0 | ||
pytest>=6.2.4 | ||
fastjsonschema~=2.15.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ networkx~=2.5 | |
numpy>=1.16.6,<1.20 | ||
defusedxml>=0.7.1 | ||
requests>=2.25.1 | ||
fastjsonschema~=2.15.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ numpy>=1.16.6,<1.20 | |
defusedxml>=0.7.1 | ||
urllib3>=1.26.4 | ||
requests>=2.25.1 | ||
fastjsonschema~=2.15.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ networkx~=2.5 | |
numpy>=1.16.6,<1.20 | ||
defusedxml>=0.7.1 | ||
requests>=2.25.1 | ||
fastjsonschema~=2.15.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ networkx~=2.5 | |
numpy>=1.16.6,<1.19 | ||
defusedxml>=0.7.1 | ||
requests>=2.25.1 | ||
fastjsonschema~=2.15.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ networkx~=2.5 | |
numpy>=1.16.6,<1.20 | ||
defusedxml>=0.7.1 | ||
requests>=2.25.1 | ||
fastjsonschema~=2.15.1 |
40 changes: 40 additions & 0 deletions
40
model-optimizer/unit_tests/mo/utils/custom_replacement_config_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright (C) 2018-2021 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import os | ||
import unittest | ||
from fnmatch import fnmatch | ||
from generator import generator, generate | ||
|
||
from mo.utils.custom_replacement_config import load_and_validate_json_config | ||
from mo.utils.error import Error | ||
from mo.utils.utils import get_mo_root_dir | ||
|
||
|
||
def get_json_configs(mo_root_dir): | ||
config_path = os.path.join(mo_root_dir, 'extensions', 'front') | ||
pattern = "*.json" | ||
config_files_list = [] | ||
for path, subdirs, files in os.walk(config_path): | ||
for name in files: | ||
if fnmatch(name, pattern): | ||
config_files_list.append((os.path.join(path, name),)) | ||
return config_files_list | ||
|
||
@generator | ||
class TestSchema(unittest.TestCase): | ||
base_dir = get_mo_root_dir() | ||
schema_file = os.path.join(base_dir, 'mo', 'utils', 'schema.json') | ||
transformation_configs = get_json_configs(base_dir) | ||
test_json1 = '[{"id": "", "match_kind": "general", "custom_attributes": {}}]' | ||
test_json2 = '[{"id": "someid", "match_kind": "abc", "custom_attributes": {}}]' | ||
|
||
@generate(*transformation_configs) | ||
def test_schema_file(self, transformation_config): | ||
self.assertTrue(load_and_validate_json_config(transformation_config)) | ||
|
||
def test_schema_id_empty(self): | ||
self.assertRaises(Error, load_and_validate_json_config, self.test_json1) | ||
|
||
def test_schema_match_kind_wrong(self): | ||
self.assertRaises(Error, load_and_validate_json_config, self.test_json2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pymongo | ||
Jinja2 | ||
PyYAML | ||
fastjsonschema~=2.15.1 | ||
|
||
h5py<3.0.0 # WA for OMZ Keras models. Details: https://github.com/openvinotoolkit/open_model_zoo/issues/1806 |