diff --git a/src/vss_tools/model.py b/src/vss_tools/model.py index 362a191c..263562da 100644 --- a/src/vss_tools/model.py +++ b/src/vss_tools/model.py @@ -7,7 +7,7 @@ # SPDX-License-Identifier: MPL-2.0 import re from enum import Enum -from typing import Any, TypeAlias +from typing import Any, Literal, TypeAlias import jsonschema from pydantic import ( @@ -33,7 +33,15 @@ resolve_datatype, ) -EXPORT_EXCLUDE_ATTRIBUTES = ["delete", "instantiate", "fqn", "arraysize", "aggregate", "is_instance"] +EXPORT_EXCLUDE_ATTRIBUTES = [ + "delete", + "instantiate", + "fqn", + "arraysize", + "aggregate", + "is_instance", + "instances_relation", +] class ModelException(Exception): @@ -139,6 +147,7 @@ def ensure_description(self) -> Self: class VSSDataBranch(VSSData): instances: Any = None + instances_relation: Literal["child", "sibling"] = "child" aggregate: bool = False is_instance: bool = False diff --git a/src/vss_tools/tree.py b/src/vss_tools/tree.py index 10b43044..a762dc10 100644 --- a/src/vss_tools/tree.py +++ b/src/vss_tools/tree.py @@ -56,6 +56,10 @@ class NoVSSDataException(Exception): pass +class InvalidInstanceNodeException(Exception): + pass + + class VSSNode(Node): # type: ignore[misc] """ Our Anytree node class @@ -207,6 +211,10 @@ def expand_instances(self) -> None: n_instance_nodes += len(instance_nodes) iterations += 1 for instance_node in instance_nodes: + data = instance_node.get_vss_data() + if not isinstance(data, VSSDataBranch): + raise InvalidInstanceNodeException(instance_node.get_fqn()) + log.debug(f"'{instance_node.get_fqn()}', expanding...") # Copy the reference node for creating instances instance_node_copy = deepcopy(instance_node) @@ -233,6 +241,13 @@ def expand_instances(self) -> None: # Roots to attach generated nodes # Initialized with the instance node itself roots = [instance_node] + + if data.instances_relation == "sibling": + if instance_node.parent is None: + instance_node.data.instances = [] # type: ignore + continue + roots = [instance_node.parent] + log.debug(f"Roots: {[r.get_fqn() for r in roots]}") # We want to keep track of generated nodes @@ -241,7 +256,7 @@ def expand_instances(self) -> None: generated_instance_nodes = [] # On every iteration, we get back new nodes to attach new instances to (roots) # as well as the nodes that have been generated - for instance in instance_node.data.instances: # type: ignore + for instance in data.instances: roots, generated = expand_instance(roots, instance_node_copy, instance) generated_instance_nodes.extend(generated) @@ -483,7 +498,6 @@ def expand_instance( # Instances could be again a list of strings # We want to harmonize that # The info however is used to decide what new root points to return - requested_instances = [] if isinstance(instance, list): requested_instances = instance else: diff --git a/tests/vspec/test_instances/expected.apigear/A.module.yaml b/tests/vspec/test_instances/expected.apigear/A.module.yaml index d7aa28eb..ea0ac075 100644 --- a/tests/vspec/test_instances/expected.apigear/A.module.yaml +++ b/tests/vspec/test_instances/expected.apigear/A.module.yaml @@ -22,3 +22,38 @@ interfaces: - name: C type: int32 description: This description will also exist multiple times. +- name: A_Y + properties: + - name: Count + type: int32 + description: d +- name: A_X_B + properties: + - name: Count + type: int32 + description: d +- name: A_X_C + properties: + - name: Count + type: int32 + description: d +- name: A_X_B1 + properties: + - name: Value + type: bool + description: d +- name: A_X_B2 + properties: + - name: Value + type: bool + description: d +- name: A_X_C1 + properties: + - name: Value + type: bool + description: d +- name: A_X_C2 + properties: + - name: Value + type: bool + description: d diff --git a/tests/vspec/test_instances/expected.csv b/tests/vspec/test_instances/expected.csv index 0207454c..ac4f3df8 100644 --- a/tests/vspec/test_instances/expected.csv +++ b/tests/vspec/test_instances/expected.csv @@ -11,3 +11,26 @@ A.B.Row2.Left,branch,,,,,,This description will be duplicated.,This comment will A.B.Row2.Left.C,sensor,int8,,km,,,This description will also exist multiple times.,As well as this comment.,, A.B.Row2.Right,branch,,,,,,This description will be duplicated.,This comment will be duplicated,, A.B.Row2.Right.C,sensor,int8,,km,,,This description will also exist multiple times.,As well as this comment.,, +A.Y,branch,,,,,,d,,, +A.Y.Count,attribute,uint8,,,,,d,,, +A.X,branch,,,,,,d,,, +A.X.B,branch,,,,,,d,,, +A.X.B.Count,attribute,uint8,,,,,d,,, +A.X.C,branch,,,,,,d,,, +A.X.C.Count,attribute,uint8,,,,,d,,, +A.X.B1,branch,,,,,,d,,, +A.X.B1.Value,sensor,boolean,,,,,d,,, +A.X.B2,branch,,,,,,d,,, +A.X.B2.Value,sensor,boolean,,,,,d,,, +A.X.C1,branch,,,,,,d,,, +A.X.C1.Value,sensor,boolean,,,,,d,,, +A.X.C2,branch,,,,,,d,,, +A.X.C2.Value,sensor,boolean,,,,,d,,, +A.Y1,branch,,,,,,d,,, +A.Y1.Z,branch,,,,,,d,,, +A.Y1.Z.Z1,branch,,,,,,d,,, +A.Y1.Z.Z2,branch,,,,,,d,,, +A.Y2,branch,,,,,,d,,, +A.Y2.Z,branch,,,,,,d,,, +A.Y2.Z.Z1,branch,,,,,,d,,, +A.Y2.Z.Z2,branch,,,,,,d,,, diff --git a/tests/vspec/test_instances/expected.ddsidl b/tests/vspec/test_instances/expected.ddsidl index 022d4d26..e47d4959 100644 --- a/tests/vspec/test_instances/expected.ddsidl +++ b/tests/vspec/test_instances/expected.ddsidl @@ -56,4 +56,110 @@ octet value; }; +module Y +{ +struct Count +{ +octet value; +//const string type ="attribute"; +//const string description="d"; +}; +}; + +module X +{ +module B +{ +struct Count +{ +octet value; +//const string type ="attribute"; +//const string description="d"; +}; +}; + +module C +{ +struct Count +{ +octet value; +//const string type ="attribute"; +//const string description="d"; +}; +}; + +module B1 +{ +struct Value +{ +boolean value; +//const string type ="sensor"; +//const string description="d"; +}; +}; + +module B2 +{ +struct Value +{ +boolean value; +//const string type ="sensor"; +//const string description="d"; +}; +}; + +module C1 +{ +struct Value +{ +boolean value; +//const string type ="sensor"; +//const string description="d"; +}; +}; + +module C2 +{ +struct Value +{ +boolean value; +//const string type ="sensor"; +//const string description="d"; +}; +}; + +}; + +module Y1 +{ +module Z +{ +module Z1 +{ +}; + +module Z2 +{ +}; + +}; + +}; + +module Y2 +{ +module Z +{ +module Z1 +{ +}; + +module Z2 +{ +}; + +}; + +}; + }; diff --git a/tests/vspec/test_instances/expected.franca b/tests/vspec/test_instances/expected.franca index af5ea16d..69795f59 100644 --- a/tests/vspec/test_instances/expected.franca +++ b/tests/vspec/test_instances/expected.franca @@ -70,5 +70,104 @@ const SignalSpec[] signal_spec = [ description: "This description will also exist multiple times.", datatype: "int8", unit: "km" +}, +{ name: "A.Y", + type: "branch", + description: "d" +}, +{ name: "A.Y.Count", + type: "attribute", + description: "d", + datatype: "uint8" +}, +{ name: "A.X", + type: "branch", + description: "d" +}, +{ name: "A.X.B", + type: "branch", + description: "d" +}, +{ name: "A.X.B.Count", + type: "attribute", + description: "d", + datatype: "uint8" +}, +{ name: "A.X.C", + type: "branch", + description: "d" +}, +{ name: "A.X.C.Count", + type: "attribute", + description: "d", + datatype: "uint8" +}, +{ name: "A.X.B1", + type: "branch", + description: "d" +}, +{ name: "A.X.B1.Value", + type: "sensor", + description: "d", + datatype: "boolean" +}, +{ name: "A.X.B2", + type: "branch", + description: "d" +}, +{ name: "A.X.B2.Value", + type: "sensor", + description: "d", + datatype: "boolean" +}, +{ name: "A.X.C1", + type: "branch", + description: "d" +}, +{ name: "A.X.C1.Value", + type: "sensor", + description: "d", + datatype: "boolean" +}, +{ name: "A.X.C2", + type: "branch", + description: "d" +}, +{ name: "A.X.C2.Value", + type: "sensor", + description: "d", + datatype: "boolean" +}, +{ name: "A.Y1", + type: "branch", + description: "d" +}, +{ name: "A.Y1.Z", + type: "branch", + description: "d" +}, +{ name: "A.Y1.Z.Z1", + type: "branch", + description: "d" +}, +{ name: "A.Y1.Z.Z2", + type: "branch", + description: "d" +}, +{ name: "A.Y2", + type: "branch", + description: "d" +}, +{ name: "A.Y2.Z", + type: "branch", + description: "d" +}, +{ name: "A.Y2.Z.Z1", + type: "branch", + description: "d" +}, +{ name: "A.Y2.Z.Z2", + type: "branch", + description: "d" } ] \ No newline at end of file diff --git a/tests/vspec/test_instances/expected.go b/tests/vspec/test_instances/expected.go index 69085a10..00a27700 100644 --- a/tests/vspec/test_instances/expected.go +++ b/tests/vspec/test_instances/expected.go @@ -1,7 +1,11 @@ package vss -type A struct { +type AI1 struct { B BI2 + Y Y + X XI1 + Y1 A + Y2 A } type BI2 struct { Row1 BI1 @@ -14,3 +18,38 @@ type BI1 struct { type B struct { C int8 } +type Y struct { + Count uint8 +} +type XI1 struct { + B I1B + C I1C + B1 X + B2 X + C1 X + C2 X +} +type I1B struct { + Count uint8 +} +type I1C struct { + Count uint8 +} +type X struct { + Value bool +} +type A struct { + Z Y2ZI1 +} +type ZI1 struct { + Z1 Z + Z2 Z +} +type Z struct { +} +type Y2ZI1 struct { + Z1 Y2Z + Z2 Y2Z +} +type Y2Z struct { +} diff --git a/tests/vspec/test_instances/expected.json b/tests/vspec/test_instances/expected.json index 191e2fed..9a783cba 100644 --- a/tests/vspec/test_instances/expected.json +++ b/tests/vspec/test_instances/expected.json @@ -1 +1 @@ -{"A": {"children": {"B": {"children": {"Row1": {"children": {"Left": {"children": {"C": {"comment": "As well as this comment.", "datatype": "int8", "description": "This description will also exist multiple times.", "type": "sensor", "unit": "km"}}, "comment": "This comment will be duplicated", "description": "This description will be duplicated.", "type": "branch"}, "Right": {"children": {"C": {"comment": "As well as this comment.", "datatype": "int8", "description": "This description will also exist multiple times.", "type": "sensor", "unit": "km"}}, "comment": "This comment will be duplicated", "description": "This description will be duplicated.", "type": "branch"}}, "comment": "This comment will be duplicated", "description": "This description will be duplicated.", "type": "branch"}, "Row2": {"children": {"Left": {"children": {"C": {"comment": "As well as this comment.", "datatype": "int8", "description": "This description will also exist multiple times.", "type": "sensor", "unit": "km"}}, "comment": "This comment will be duplicated", "description": "This description will be duplicated.", "type": "branch"}, "Right": {"children": {"C": {"comment": "As well as this comment.", "datatype": "int8", "description": "This description will also exist multiple times.", "type": "sensor", "unit": "km"}}, "comment": "This comment will be duplicated", "description": "This description will be duplicated.", "type": "branch"}}, "comment": "This comment will be duplicated", "description": "This description will be duplicated.", "type": "branch"}}, "comment": "This comment will be duplicated", "description": "This description will be duplicated.", "type": "branch"}}, "description": "Branch A.", "type": "branch"}} \ No newline at end of file +{"A": {"children": {"B": {"children": {"Row1": {"children": {"Left": {"children": {"C": {"comment": "As well as this comment.", "datatype": "int8", "description": "This description will also exist multiple times.", "type": "sensor", "unit": "km"}}, "comment": "This comment will be duplicated", "description": "This description will be duplicated.", "type": "branch"}, "Right": {"children": {"C": {"comment": "As well as this comment.", "datatype": "int8", "description": "This description will also exist multiple times.", "type": "sensor", "unit": "km"}}, "comment": "This comment will be duplicated", "description": "This description will be duplicated.", "type": "branch"}}, "comment": "This comment will be duplicated", "description": "This description will be duplicated.", "type": "branch"}, "Row2": {"children": {"Left": {"children": {"C": {"comment": "As well as this comment.", "datatype": "int8", "description": "This description will also exist multiple times.", "type": "sensor", "unit": "km"}}, "comment": "This comment will be duplicated", "description": "This description will be duplicated.", "type": "branch"}, "Right": {"children": {"C": {"comment": "As well as this comment.", "datatype": "int8", "description": "This description will also exist multiple times.", "type": "sensor", "unit": "km"}}, "comment": "This comment will be duplicated", "description": "This description will be duplicated.", "type": "branch"}}, "comment": "This comment will be duplicated", "description": "This description will be duplicated.", "type": "branch"}}, "comment": "This comment will be duplicated", "description": "This description will be duplicated.", "type": "branch"}, "X": {"children": {"B": {"children": {"Count": {"datatype": "uint8", "description": "d", "type": "attribute"}}, "description": "d", "type": "branch"}, "B1": {"children": {"Value": {"datatype": "boolean", "description": "d", "type": "sensor"}}, "description": "d", "type": "branch"}, "B2": {"children": {"Value": {"datatype": "boolean", "description": "d", "type": "sensor"}}, "description": "d", "type": "branch"}, "C": {"children": {"Count": {"datatype": "uint8", "description": "d", "type": "attribute"}}, "description": "d", "type": "branch"}, "C1": {"children": {"Value": {"datatype": "boolean", "description": "d", "type": "sensor"}}, "description": "d", "type": "branch"}, "C2": {"children": {"Value": {"datatype": "boolean", "description": "d", "type": "sensor"}}, "description": "d", "type": "branch"}}, "description": "d", "type": "branch"}, "Y": {"children": {"Count": {"datatype": "uint8", "description": "d", "type": "attribute"}}, "description": "d", "type": "branch"}, "Y1": {"children": {"Z": {"children": {"Z1": {"description": "d", "type": "branch"}, "Z2": {"description": "d", "type": "branch"}}, "description": "d", "type": "branch"}}, "description": "d", "type": "branch"}, "Y2": {"children": {"Z": {"children": {"Z1": {"description": "d", "type": "branch"}, "Z2": {"description": "d", "type": "branch"}}, "description": "d", "type": "branch"}}, "description": "d", "type": "branch"}}, "description": "Branch A.", "type": "branch"}} \ No newline at end of file diff --git a/tests/vspec/test_instances/expected.jsonschema b/tests/vspec/test_instances/expected.jsonschema index e54b3a3a..a822b628 100644 --- a/tests/vspec/test_instances/expected.jsonschema +++ b/tests/vspec/test_instances/expected.jsonschema @@ -1 +1 @@ -{"$schema": "https://json-schema.org/draft/2020-12/schema", "title": "A", "type": "object", "description": "Branch A.", "properties": {"B": {"type": "object", "description": "This description will be duplicated.", "properties": {"Row1": {"type": "object", "description": "This description will be duplicated.", "properties": {"Left": {"type": "object", "description": "This description will be duplicated.", "properties": {"C": {"type": "integer", "description": "This description will also exist multiple times.", "minimum": -128, "maximum": 127}}}, "Right": {"type": "object", "description": "This description will be duplicated.", "properties": {"C": {"type": "integer", "description": "This description will also exist multiple times.", "minimum": -128, "maximum": 127}}}}}, "Row2": {"type": "object", "description": "This description will be duplicated.", "properties": {"Left": {"type": "object", "description": "This description will be duplicated.", "properties": {"C": {"type": "integer", "description": "This description will also exist multiple times.", "minimum": -128, "maximum": 127}}}, "Right": {"type": "object", "description": "This description will be duplicated.", "properties": {"C": {"type": "integer", "description": "This description will also exist multiple times.", "minimum": -128, "maximum": 127}}}}}}}}} \ No newline at end of file +{"$schema": "https://json-schema.org/draft/2020-12/schema", "title": "A", "type": "object", "description": "Branch A.", "properties": {"B": {"type": "object", "description": "This description will be duplicated.", "properties": {"Row1": {"type": "object", "description": "This description will be duplicated.", "properties": {"Left": {"type": "object", "description": "This description will be duplicated.", "properties": {"C": {"type": "integer", "description": "This description will also exist multiple times.", "minimum": -128, "maximum": 127}}}, "Right": {"type": "object", "description": "This description will be duplicated.", "properties": {"C": {"type": "integer", "description": "This description will also exist multiple times.", "minimum": -128, "maximum": 127}}}}}, "Row2": {"type": "object", "description": "This description will be duplicated.", "properties": {"Left": {"type": "object", "description": "This description will be duplicated.", "properties": {"C": {"type": "integer", "description": "This description will also exist multiple times.", "minimum": -128, "maximum": 127}}}, "Right": {"type": "object", "description": "This description will be duplicated.", "properties": {"C": {"type": "integer", "description": "This description will also exist multiple times.", "minimum": -128, "maximum": 127}}}}}}}, "Y": {"type": "object", "description": "d", "properties": {"Count": {"type": "integer", "description": "d", "minimum": 0, "maximum": 255}}}, "X": {"type": "object", "description": "d", "properties": {"B": {"type": "object", "description": "d", "properties": {"Count": {"type": "integer", "description": "d", "minimum": 0, "maximum": 255}}}, "C": {"type": "object", "description": "d", "properties": {"Count": {"type": "integer", "description": "d", "minimum": 0, "maximum": 255}}}, "B1": {"type": "object", "description": "d", "properties": {"Value": {"type": "boolean", "description": "d"}}}, "B2": {"type": "object", "description": "d", "properties": {"Value": {"type": "boolean", "description": "d"}}}, "C1": {"type": "object", "description": "d", "properties": {"Value": {"type": "boolean", "description": "d"}}}, "C2": {"type": "object", "description": "d", "properties": {"Value": {"type": "boolean", "description": "d"}}}}}, "Y1": {"type": "object", "description": "d", "properties": {"Z": {"type": "object", "description": "d", "properties": {"Z1": {"type": "object", "description": "d", "properties": {}}, "Z2": {"type": "object", "description": "d", "properties": {}}}}}}, "Y2": {"type": "object", "description": "d", "properties": {"Z": {"type": "object", "description": "d", "properties": {"Z1": {"type": "object", "description": "d", "properties": {}}, "Z2": {"type": "object", "description": "d", "properties": {}}}}}}}} \ No newline at end of file diff --git a/tests/vspec/test_instances/expected.plantuml b/tests/vspec/test_instances/expected.plantuml index 63d61bda..fa24fefe 100644 --- a/tests/vspec/test_instances/expected.plantuml +++ b/tests/vspec/test_instances/expected.plantuml @@ -1,5 +1,9 @@ -class A { +class AIS { b : PB.BIS0 + y : PY.Y + x : PX.XIS + y1 : A + y2 : A } ' This description will be duplicated. package PB { @@ -18,3 +22,57 @@ package PB { c : int8 } } +' d +package PY { + class Y { + + ' attribute: d + count : uint8 + } +} +' d +package PX { + class XIS { + b : PX.PB.B + c : PX.PC.C + b1 : PX.X + b2 : PX.X + c1 : PX.X + c2 : PX.X + } + ' d + package PB { + class B { + + ' attribute: d + count : uint8 + } + } + ' d + package PC { + class C { + + ' attribute: d + count : uint8 + } + } + class X { + + ' sensor: d + value : boolean + } +} +class A { + z : PZ.ZIS +} +' d +package PZ { + class ZIS { + + ' branch: d + z1 : None + + ' branch: d + z2 : None + } +} diff --git a/tests/vspec/test_instances/expected.samm/com.covesa.vss.spec/1.0.0/A.ttl b/tests/vspec/test_instances/expected.samm/com.covesa.vss.spec/1.0.0/A.ttl index 72a0f3d4..27d79382 100644 --- a/tests/vspec/test_instances/expected.samm/com.covesa.vss.spec/1.0.0/A.ttl +++ b/tests/vspec/test_instances/expected.samm/com.covesa.vss.spec/1.0.0/A.ttl @@ -20,6 +20,6 @@ Description: Branch A."""@en ; samm:name "ACharacteristic" . :AEntity a samm:Entity ; - samm:properties ( [ samm:property :b; samm:payloadName "b" ] ) . + samm:properties ( [ samm:property :ab; samm:payloadName "b" ] [ samm:property :y; samm:payloadName "y" ] [ samm:property :x; samm:payloadName "x" ] ) . diff --git a/tests/vspec/test_instances/expected.samm/com.covesa.vss.spec/1.0.0/Ab.ttl b/tests/vspec/test_instances/expected.samm/com.covesa.vss.spec/1.0.0/Ab.ttl new file mode 100644 index 00000000..f77df3ec --- /dev/null +++ b/tests/vspec/test_instances/expected.samm/com.covesa.vss.spec/1.0.0/Ab.ttl @@ -0,0 +1,78 @@ +@prefix : . +@prefix samm: . +@prefix samm-c: . +@prefix unit: . +@prefix xsd: . + +:Ab a samm:Aspect ; + samm:events () ; + samm:operations () ; + samm:preferredName "B"@en ; + samm:properties ( :ab ) . + +:ab a samm:Property ; + samm:characteristic :AbInstanceSingleEntity ; + samm:preferredName "AB"@en . + +:abRow1 a samm:Property ; + samm:characteristic :AbRowSingleEntity ; + samm:preferredName "Ab Row1"@en . + +:abRow2 a samm:Property ; + samm:characteristic :AbRowSingleEntity ; + samm:preferredName "Ab Row2"@en . + +:abRowLeft a samm:Property ; + samm:characteristic :AbCharacteristic ; + samm:preferredName "Ab Row Left"@en . + +:abRowRight a samm:Property ; + samm:characteristic :AbCharacteristic ; + samm:preferredName "Ab Row Right"@en . + +:bc a samm:Property ; + samm:characteristic :BcCharacteristic ; + samm:preferredName "BC"@en . + +:AbEntity a samm:Entity ; + samm:properties ( [ samm:property :bc; samm:payloadName "c" ] ) . + +:AbInstanceEntity a samm:Entity ; + samm:properties ( [ samm:property :abRow1; samm:optional true; samm:payloadName "row1" ] [ samm:property :abRow2; samm:optional true; samm:payloadName "row2" ] ) . + +:AbInstanceSingleEntity a samm-c:SingleEntity ; + samm:dataType :AbInstanceEntity ; + samm:name "AbInstance" ; + samm:preferredName "Ab Instance"@en . + +:AbRowEntity a samm:Entity ; + samm:properties ( [ samm:property :abRowLeft; samm:optional true; samm:payloadName "left" ] [ samm:property :abRowRight; samm:optional true; samm:payloadName "right" ] ) . + +:BcCharacteristic a samm-c:Measurement ; + samm-c:unit unit:kilometre ; + samm:dataType xsd:byte ; + samm:description """ +VSS path : A.B.C + +Description: This description will also exist multiple times. + +Comment : As well as this comment. + +Unit : km"""@en . + +:AbCharacteristic a samm:Characteristic ; + samm:dataType :AbEntity ; + samm:description """ +VSS path : A.B + +Description: This description will be duplicated. + +Comment : This comment will be duplicated"""@en ; + samm:name "AbCharacteristic" . + +:AbRowSingleEntity a samm-c:SingleEntity ; + samm:dataType :AbRowEntity ; + samm:name "AbRow" ; + samm:preferredName "Ab Row"@en . + + diff --git a/tests/vspec/test_instances/expected.samm/com.covesa.vss.spec/1.0.0/B.ttl b/tests/vspec/test_instances/expected.samm/com.covesa.vss.spec/1.0.0/B.ttl deleted file mode 100644 index c25cca76..00000000 --- a/tests/vspec/test_instances/expected.samm/com.covesa.vss.spec/1.0.0/B.ttl +++ /dev/null @@ -1,78 +0,0 @@ -@prefix : . -@prefix samm: . -@prefix samm-c: . -@prefix unit: . -@prefix xsd: . - -:B a samm:Aspect ; - samm:events () ; - samm:operations () ; - samm:preferredName "B"@en ; - samm:properties ( :b ) . - -:b a samm:Property ; - samm:characteristic :BInstanceSingleEntity ; - samm:preferredName "B"@en . - -:bRow1 a samm:Property ; - samm:characteristic :BRowSingleEntity ; - samm:preferredName "B Row1"@en . - -:bRow2 a samm:Property ; - samm:characteristic :BRowSingleEntity ; - samm:preferredName "B Row2"@en . - -:bRowLeft a samm:Property ; - samm:characteristic :BCharacteristic ; - samm:preferredName "B Row Left"@en . - -:bRowRight a samm:Property ; - samm:characteristic :BCharacteristic ; - samm:preferredName "B Row Right"@en . - -:c a samm:Property ; - samm:characteristic :CCharacteristic ; - samm:preferredName "C"@en . - -:BEntity a samm:Entity ; - samm:properties ( [ samm:property :c; samm:payloadName "c" ] ) . - -:BInstanceEntity a samm:Entity ; - samm:properties ( [ samm:property :bRow1; samm:optional true; samm:payloadName "row1" ] [ samm:property :bRow2; samm:optional true; samm:payloadName "row2" ] ) . - -:BInstanceSingleEntity a samm-c:SingleEntity ; - samm:dataType :BInstanceEntity ; - samm:name "BInstance" ; - samm:preferredName "B Instance"@en . - -:BRowEntity a samm:Entity ; - samm:properties ( [ samm:property :bRowLeft; samm:optional true; samm:payloadName "left" ] [ samm:property :bRowRight; samm:optional true; samm:payloadName "right" ] ) . - -:CCharacteristic a samm-c:Measurement ; - samm-c:unit unit:kilometre ; - samm:dataType xsd:byte ; - samm:description """ -VSS path : A.B.C - -Description: This description will also exist multiple times. - -Comment : As well as this comment. - -Unit : km"""@en . - -:BCharacteristic a samm:Characteristic ; - samm:dataType :BEntity ; - samm:description """ -VSS path : A.B - -Description: This description will be duplicated. - -Comment : This comment will be duplicated"""@en ; - samm:name "BCharacteristic" . - -:BRowSingleEntity a samm-c:SingleEntity ; - samm:dataType :BRowEntity ; - samm:name "BRow" ; - samm:preferredName "B Row"@en . - - diff --git a/tests/vspec/test_instances/expected.samm/com.covesa.vss.spec/1.0.0/X.ttl b/tests/vspec/test_instances/expected.samm/com.covesa.vss.spec/1.0.0/X.ttl new file mode 100644 index 00000000..28cd473a --- /dev/null +++ b/tests/vspec/test_instances/expected.samm/com.covesa.vss.spec/1.0.0/X.ttl @@ -0,0 +1,133 @@ +@prefix : . +@prefix samm: . +@prefix samm-c: . +@prefix xsd: . + +:X a samm:Aspect ; + samm:events () ; + samm:operations () ; + samm:preferredName "X"@en ; + samm:properties ( :x ) . + +:bCount a samm:Property ; + samm:characteristic :BCountCharacteristic ; + samm:preferredName "B Count"@en . + +:bValue a samm:Property ; + samm:characteristic :BValueCharacteristic ; + samm:preferredName "B Value"@en . + +:cValue a samm:Property ; + samm:characteristic :CValueCharacteristic ; + samm:preferredName "C Value"@en . + +:x a samm:Property ; + samm:characteristic :XCharacteristic ; + samm:preferredName "X"@en . + +:xb a samm:Property ; + samm:characteristic :XbInstanceSingleEntity ; + samm:preferredName "XB"@en . + +:xbb1 a samm:Property ; + samm:characteristic :XbCharacteristic ; + samm:preferredName "XbB1"@en . + +:xbb2 a samm:Property ; + samm:characteristic :XbCharacteristic ; + samm:preferredName "XbB2"@en . + +:xc a samm:Property ; + samm:characteristic :XcInstanceSingleEntity ; + samm:preferredName "XC"@en . + +:xcCount a samm:Property ; + samm:characteristic :XcCountCharacteristic ; + samm:preferredName "XC Count"@en . + +:xcc1 a samm:Property ; + samm:characteristic :XcCharacteristic ; + samm:preferredName "XcC1"@en . + +:xcc2 a samm:Property ; + samm:characteristic :XcCharacteristic ; + samm:preferredName "XcC2"@en . + +:BCountCharacteristic a samm:Characteristic ; + samm:dataType xsd:unsignedByte ; + samm:description """ +VSS path : A.X.B.Count + +Description: d"""@en . + +:BValueCharacteristic a samm:Characteristic ; + samm:dataType xsd:boolean ; + samm:description """ +VSS path : A.X.B.Value + +Description: d"""@en . + +:CValueCharacteristic a samm:Characteristic ; + samm:dataType xsd:boolean ; + samm:description """ +VSS path : A.X.C.Value + +Description: d"""@en . + +:XCharacteristic a samm:Characteristic ; + samm:dataType :XEntity ; + samm:description """ +VSS path : A.X + +Description: d"""@en ; + samm:name "XCharacteristic" . + +:XEntity a samm:Entity ; + samm:properties ( [ samm:property :xb; samm:payloadName "b" ] [ samm:property :xc; samm:payloadName "c" ] ) . + +:XbEntity a samm:Entity ; + samm:properties ( [ samm:property :bCount; samm:payloadName "count" ] [ samm:property :bValue; samm:payloadName "value" ] ) . + +:XbInstanceEntity a samm:Entity ; + samm:properties ( [ samm:property :xbb1; samm:optional true; samm:payloadName "b1" ] [ samm:property :xbb2; samm:optional true; samm:payloadName "b2" ] ) . + +:XbInstanceSingleEntity a samm-c:SingleEntity ; + samm:dataType :XbInstanceEntity ; + samm:name "XbInstance" ; + samm:preferredName "Xb Instance"@en . + +:XcCountCharacteristic a samm:Characteristic ; + samm:dataType xsd:unsignedByte ; + samm:description """ +VSS path : A.X.C.Count + +Description: d"""@en . + +:XcEntity a samm:Entity ; + samm:properties ( [ samm:property :xcCount; samm:payloadName "count" ] [ samm:property :cValue; samm:payloadName "value" ] ) . + +:XcInstanceEntity a samm:Entity ; + samm:properties ( [ samm:property :xcc1; samm:optional true; samm:payloadName "c1" ] [ samm:property :xcc2; samm:optional true; samm:payloadName "c2" ] ) . + +:XcInstanceSingleEntity a samm-c:SingleEntity ; + samm:dataType :XcInstanceEntity ; + samm:name "XcInstance" ; + samm:preferredName "Xc Instance"@en . + +:XbCharacteristic a samm:Characteristic ; + samm:dataType :XbEntity ; + samm:description """ +VSS path : A.X.B + +Description: d"""@en ; + samm:name "XbCharacteristic" . + +:XcCharacteristic a samm:Characteristic ; + samm:dataType :XcEntity ; + samm:description """ +VSS path : A.X.C + +Description: d"""@en ; + samm:name "XcCharacteristic" . + + diff --git a/tests/vspec/test_instances/expected.samm/com.covesa.vss.spec/1.0.0/Y.ttl b/tests/vspec/test_instances/expected.samm/com.covesa.vss.spec/1.0.0/Y.ttl new file mode 100644 index 00000000..a6935013 --- /dev/null +++ b/tests/vspec/test_instances/expected.samm/com.covesa.vss.spec/1.0.0/Y.ttl @@ -0,0 +1,86 @@ +@prefix : . +@prefix samm: . +@prefix samm-c: . +@prefix xsd: . + +:Y a samm:Aspect ; + samm:events () ; + samm:operations () ; + samm:preferredName "Y"@en ; + samm:properties ( :y ) . + +:y a samm:Property ; + samm:characteristic :YInstanceSingleEntity ; + samm:preferredName "Y"@en . + +:yCount a samm:Property ; + samm:characteristic :YCountCharacteristic ; + samm:preferredName "Y Count"@en . + +:yy1 a samm:Property ; + samm:characteristic :YCharacteristic ; + samm:preferredName "YY1"@en . + +:yy2 a samm:Property ; + samm:characteristic :YCharacteristic ; + samm:preferredName "YY2"@en . + +:z a samm:Property ; + samm:characteristic :ZCharacteristic, + :ZInstanceSingleEntity ; + samm:preferredName "Z"@en . + +:zz1 a samm:Property ; + samm:characteristic :ZCharacteristic ; + samm:preferredName "ZZ1"@en . + +:zz2 a samm:Property ; + samm:characteristic :ZCharacteristic ; + samm:preferredName "ZZ2"@en . + +:YCountCharacteristic a samm:Characteristic ; + samm:dataType xsd:unsignedByte ; + samm:description """ +VSS path : A.Y.Count + +Description: d"""@en . + +:YEntity a samm:Entity ; + samm:properties ( [ samm:property :yCount; samm:payloadName "count" ] [ samm:property :z; samm:payloadName "z" ] ) . + +:YInstanceEntity a samm:Entity ; + samm:properties ( [ samm:property :yy1; samm:optional true; samm:payloadName "y1" ] [ samm:property :yy2; samm:optional true; samm:payloadName "y2" ] ) . + +:YInstanceSingleEntity a samm-c:SingleEntity ; + samm:dataType :YInstanceEntity ; + samm:name "YInstance" ; + samm:preferredName "Y Instance"@en . + +:ZEntity a samm:Entity . + +:ZInstanceEntity a samm:Entity ; + samm:properties ( [ samm:property :zz1; samm:optional true; samm:payloadName "z1" ] [ samm:property :zz2; samm:optional true; samm:payloadName "z2" ] ) . + +:ZInstanceSingleEntity a samm-c:SingleEntity ; + samm:dataType :ZInstanceEntity ; + samm:name "ZInstance" ; + samm:preferredName "Z Instance"@en . + +:YCharacteristic a samm:Characteristic ; + samm:dataType :YEntity ; + samm:description """ +VSS path : A.Y + +Description: d"""@en ; + samm:name "YCharacteristic" . + +:ZCharacteristic a samm:Characteristic ; + samm:dataType xsd:double, + :ZEntity ; + samm:description """ +VSS path : A.Y.Z + +Description: d"""@en ; + samm:name "ZCharacteristic" . + + diff --git a/tests/vspec/test_instances/expected.yaml b/tests/vspec/test_instances/expected.yaml index d0b79b3c..0346cc98 100644 --- a/tests/vspec/test_instances/expected.yaml +++ b/tests/vspec/test_instances/expected.yaml @@ -64,3 +64,102 @@ A.B.Row2.Right.C: comment: As well as this comment. datatype: int8 unit: km + +A.Y: + type: branch + description: d + +A.Y.Count: + type: attribute + description: d + datatype: uint8 + +A.X: + type: branch + description: d + +A.X.B: + type: branch + description: d + +A.X.B.Count: + type: attribute + description: d + datatype: uint8 + +A.X.C: + type: branch + description: d + +A.X.C.Count: + type: attribute + description: d + datatype: uint8 + +A.X.B1: + type: branch + description: d + +A.X.B1.Value: + type: sensor + description: d + datatype: boolean + +A.X.B2: + type: branch + description: d + +A.X.B2.Value: + type: sensor + description: d + datatype: boolean + +A.X.C1: + type: branch + description: d + +A.X.C1.Value: + type: sensor + description: d + datatype: boolean + +A.X.C2: + type: branch + description: d + +A.X.C2.Value: + type: sensor + description: d + datatype: boolean + +A.Y1: + type: branch + description: d + +A.Y1.Z: + type: branch + description: d + +A.Y1.Z.Z1: + type: branch + description: d + +A.Y1.Z.Z2: + type: branch + description: d + +A.Y2: + type: branch + description: d + +A.Y2.Z: + type: branch + description: d + +A.Y2.Z.Z1: + type: branch + description: d + +A.Y2.Z.Z2: + type: branch + description: d diff --git a/tests/vspec/test_instances/test.vspec b/tests/vspec/test_instances/test.vspec index b626b78c..ecd18df4 100644 --- a/tests/vspec/test_instances/test.vspec +++ b/tests/vspec/test_instances/test.vspec @@ -17,3 +17,62 @@ A.B.C: unit: km description: This description will also exist multiple times. comment: As well as this comment. + +A.Y: + type: branch + instances: Y[1,2] + instances_relation: sibling + description: d + +A.Y.Count: + type: attribute + datatype: uint8 + description: d + instantiate: false + +A.Y.Z: + type: branch + instances: Z[1,2] + description: d + +A.X: + type: branch + description: d + +A.X.B: + type: branch + description: d + instances: + - B1 + - B2 + instances_relation: sibling + +A.X.B.Count: + type: attribute + datatype: uint8 + instantiate: false + description: d + +A.X.B.Value: + type: sensor + datatype: boolean + description: d + +A.X.C: + type: branch + description: d + instances: + - C1 + - C2 + instances_relation: sibling + +A.X.C.Count: + type: attribute + datatype: uint8 + instantiate: false + description: d + +A.X.C.Value: + type: sensor + datatype: boolean + description: d