1 # ============LICENSE_START====================================================
3 # =============================================================================
4 # Copyright (c) 2019-2020 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, utils
22 TEST_META = get_json_fixture("models/example-model/metadata.json")
25 def test_get_needed_formats():
26 assert dataformat_gen._get_needed_formats(TEST_META) == ["NumbersIn", "NumberOut"]
29 def test_generate_dcae_data_formats(mock_schemas):
31 Test generating data formats from the protobuf
33 test_proto_path = get_fixture_path("models/example-model/model.proto")
34 assert dataformat_gen._generate_dcae_data_formats(test_proto_path, TEST_META, utils.dataformat_schema.get(), utils.schema_schema.get()) == [
36 "self": {"name": "NumbersIn", "version": "1.0.0"},
37 "dataformatversion": "1.0.1",
42 "x": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
43 "y": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
45 "$schema": "http://json-schema.org/draft-04/schema#",
50 "self": {"name": "NumberOut", "version": "1.0.0"},
51 "dataformatversion": "1.0.1",
55 "properties": {"result": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991}},
56 "$schema": "http://json-schema.org/draft-04/schema#",
63 def test_generate_dcae_data_formats_listofm(mock_schemas):
65 Test generating data formats from the protobuf
66 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
68 test_meta = get_json_fixture("models/example-model-listofm/metadata.json")
69 test_proto_path = get_fixture_path("models/example-model-listofm/model.proto")
70 assert dataformat_gen._generate_dcae_data_formats(test_proto_path, test_meta, utils.dataformat_schema.get(), utils.schema_schema.get()) == [
72 "self": {"name": "ArgsList", "version": "1.0.0"},
73 "dataformatversion": "1.0.1",
77 "properties": {"args": {"type": "array", "items": {"$ref": "#/definitions/Args"}}},
78 "$schema": "http://json-schema.org/draft-04/schema#",
84 "x": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
85 "y": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
92 "self": {"name": "SumOut", "version": "1.0.0"},
93 "dataformatversion": "1.0.1",
100 "items": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
103 "$schema": "http://json-schema.org/draft-04/schema#",