1 # ============LICENSE_START====================================================
3 # =============================================================================
4 # Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
5 # =============================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END======================================================
19 from testing_helpers import get_json_fixture, get_fixture_path
20 from aoconversion import dataformat_gen
22 TEST_META = get_json_fixture("models/example-model/metadata.json")
23 DRAFT_4_SCHEMA = get_json_fixture("jsdraft4schema.json")
24 DF_101 = get_json_fixture("dataformat_101.json")
27 def test_get_needed_formats():
28 assert dataformat_gen._get_needed_formats(TEST_META) == ["NumbersIn", "NumberOut"]
31 def test_generate_dcae_data_formats():
33 Test generating data formats from the protobuf
35 test_proto_path = get_fixture_path("models/example-model/model.proto")
36 assert dataformat_gen._generate_dcae_data_formats(test_proto_path, TEST_META, DF_101, DRAFT_4_SCHEMA) == [
38 "self": {"name": "NumbersIn", "version": "1.0.0"},
39 "dataformatversion": "1.0.1",
44 "x": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
45 "y": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
47 "$schema": "http://json-schema.org/draft-04/schema#",
52 "self": {"name": "NumberOut", "version": "1.0.0"},
53 "dataformatversion": "1.0.1",
57 "properties": {"result": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991}},
58 "$schema": "http://json-schema.org/draft-04/schema#",
65 def test_generate_dcae_data_formats_listofm():
67 Test generating data formats from the protobuf
68 This one tests the case where definitions needs to be populated in one of the data formats because it's referenced in a "top level" message
70 test_meta = get_json_fixture("models/example-model-listofm/metadata.json")
71 test_proto_path = get_fixture_path("models/example-model-listofm/model.proto")
72 assert dataformat_gen._generate_dcae_data_formats(test_proto_path, test_meta, DF_101, DRAFT_4_SCHEMA) == [
74 "self": {"name": "ArgsList", "version": "1.0.0"},
75 "dataformatversion": "1.0.1",
79 "properties": {"args": {"type": "array", "items": {"$ref": "#/definitions/Args"}}},
80 "$schema": "http://json-schema.org/draft-04/schema#",
86 "x": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
87 "y": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
94 "self": {"name": "SumOut", "version": "1.0.0"},
95 "dataformatversion": "1.0.1",
102 "items": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
105 "$schema": "http://json-schema.org/draft-04/schema#",