Skip to content

Commit

Permalink
Add flat type file
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Jaegervall <[email protected]>
  • Loading branch information
erikbosch committed Dec 18, 2023
1 parent cba9c71 commit 3cd3708
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 6 deletions.
69 changes: 69 additions & 0 deletions tests/vspec/test_structs/VehicleDataTypesFlat.vspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright (c) 2023 Contributors to COVESA
#
# This program and the accompanying materials are made available under the
# terms of the Mozilla Public License 2.0 which is available at
# https://www.mozilla.org/en-US/MPL/2.0/
#
# SPDX-License-Identifier: MPL-2.0

# Same content as other type files, but no #include directives used.

VehicleDataTypes:
type: branch
description: Top-level branch for vehicle data types.

VehicleDataTypes.TestBranch1:
type: branch
description: "Test branch with structs and properties definitions"

VehicleDataTypes.TestBranch1.NestedStruct:
type: struct
description: "A struct that is going to be used within another struct - Nested"

VehicleDataTypes.TestBranch1.NestedStruct.x:
type: property
description: "x property"
datatype: double
min: -10

VehicleDataTypes.TestBranch1.NestedStruct.y:
type: property
description: "y property"
datatype: double
max: 10

VehicleDataTypes.TestBranch1.NestedStruct.z:
type: property
description: "z property"
datatype: double
default: 1

VehicleDataTypes.TestBranch1.ParentStruct:
type: struct
description: "A struct that is going to contain properties that are structs themselves"

VehicleDataTypes.TestBranch1.ParentStruct.x_property:
type: property
description: "A property of struct-type. The struct name is specified relative to the branch"
datatype: NestedStruct

VehicleDataTypes.TestBranch1.ParentStruct.y_property:
type: property
description: "A property of struct-type. The struct name is specified as a fully qualified name"
datatype: VehicleDataTypes.TestBranch1.NestedStruct

VehicleDataTypes.TestBranch1.ParentStruct.x_properties:
type: property
description: "A property of struct-type array and an arraysize"
datatype: NestedStruct[]
arraysize: 10

VehicleDataTypes.TestBranch1.ParentStruct.y_properties:
type: property
description: "A property of struct-type array and no arraysize"
datatype: VehicleDataTypes.TestBranch1.NestedStruct[]

VehicleDataTypes.TestBranch1.ParentStruct.z_property:
type: property
description: "A primitive property"
datatype: double
13 changes: 7 additions & 6 deletions tests/vspec/test_structs/test_data_type_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ def change_test_dir(request, monkeypatch):
monkeypatch.chdir(request.fspath.dirname)


@pytest.mark.parametrize("format,signals_out, expected_signal", [
('json', 'signals-out.json', 'expected-signals-types.json'),
('yaml', 'signals-out.yaml', 'expected-signals-types.yaml'),
('csv', 'signals-out.csv', 'expected-signals-types.csv')])
def test_data_types_export_single_file(format, signals_out, expected_signal, change_test_dir):
@pytest.mark.parametrize("format, signals_out, expected_signal, type_file", [
('json', 'signals-out.json', 'expected-signals-types.json', 'VehicleDataTypes.vspec'),
('json', 'signals-out.json', 'expected-signals-types.json', 'VehicleDataTypesFlat.vspec'),
('yaml', 'signals-out.yaml', 'expected-signals-types.yaml', 'VehicleDataTypes.vspec'),
('csv', 'signals-out.csv', 'expected-signals-types.csv', 'VehicleDataTypes.vspec')])
def test_data_types_export_single_file(format, signals_out, expected_signal, type_file, change_test_dir):
"""
Test that data types provided in vspec format are converted correctly
"""
args = ["../../../vspec2x.py", "--format", format]
if format == 'json':
args.append('--json-pretty')
args.extend(["-vt", "VehicleDataTypes.vspec", "-u", "../test_units.yaml",
args.extend(["-vt", type_file, "-u", "../test_units.yaml",
"test.vspec", signals_out, "1>", "out.txt", "2>&1"])
test_str = " ".join(args)

Expand Down

0 comments on commit 3cd3708

Please sign in to comment.