Skip to content

Commit

Permalink
Fix overlay merge error
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Jaegervall <erik.jaegervall@se.bosch.com>
  • Loading branch information
erikbosch committed Apr 5, 2024
1 parent f3aa953 commit b654d05
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 2 deletions.
90 changes: 90 additions & 0 deletions tests/vspec/test_overlay_on_instance/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,54 @@
"description": "Changed description, shall inherit comment",
"type": "sensor",
"unit": "km"
},
"TT": {
"children": {
"Left": {
"children": {
"TTT": {
"children": {
"TTTT": {
"datatype": "float",
"description": "Also some temperature.",
"type": "sensor",
"unit": "celsius"
},
"TTTY": {
"datatype": "float",
"description": "Auch some temperature.",
"type": "sensor",
"unit": "celsius"
}
},
"description": "Another branch level",
"type": "branch"
}
},
"description": "Second level instance",
"type": "branch"
},
"Right": {
"children": {
"TTT": {
"children": {
"TTTT": {
"datatype": "float",
"description": "Some temperature.",
"type": "sensor",
"unit": "celsius"
}
},
"description": "Another branch level",
"type": "branch"
}
},
"description": "Second level instance",
"type": "branch"
}
},
"description": "Second level instance",
"type": "branch"
}
},
"description": "Branch with instances, not in list",
Expand All @@ -227,6 +275,48 @@
"description": "Signal A.S.T",
"type": "sensor",
"unit": "km"
},
"TT": {
"children": {
"Left": {
"children": {
"TTT": {
"children": {
"TTTT": {
"datatype": "float",
"description": "Some temperature.",
"type": "sensor",
"unit": "celsius"
}
},
"description": "Another branch level",
"type": "branch"
}
},
"description": "Second level instance",
"type": "branch"
},
"Right": {
"children": {
"TTT": {
"children": {
"TTTT": {
"datatype": "float",
"description": "Some temperature.",
"type": "sensor",
"unit": "celsius"
}
},
"description": "Another branch level",
"type": "branch"
}
},
"description": "Second level instance",
"type": "branch"
}
},
"description": "Second level instance",
"type": "branch"
}
},
"description": "Branch with instances, not in list",
Expand Down
16 changes: 16 additions & 0 deletions tests/vspec/test_overlay_on_instance/overlay_2.vspec
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,19 @@ A.S.Up.T:
type: sensor
unit: km
description: New description, shall not inherit anything


# Complex overlay - changing description for one of TTTT
A.S.Front.TT.Left.TTT.TTTT:
datatype: float
type: sensor
unit: celsius
description: Also some temperature.


# A totally new one
A.S.Front.TT.Left.TTT.TTTY:
datatype: float
type: sensor
unit: celsius
description: Auch some temperature.
17 changes: 17 additions & 0 deletions tests/vspec/test_overlay_on_instance/test.vspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,20 @@ A.S.T:
unit: km
description: Signal A.S.T
comment: Orig comment.

# More complex example

A.S.TT:
instances: ["Left","Right"]
type: branch
description: Second level instance

A.S.TT.TTT:
type: branch
description: Another branch level

A.S.TT.TTT.TTTT:
datatype: float
type: sensor
unit: celsius
description: Some temperature.
7 changes: 5 additions & 2 deletions vspec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,11 @@ def create_instantiated_branch(branch_name, parent, nodes_to_expand):
# shall have precedence over the expanded instance
# This is handled by removing the old node from tree and
# instead merging it to the new node
existing_item.parent = None
expand_node.merge(existing_item)
# Also make sure that any children defined are copied over
for child in existing_item.children:
child.parent = expand_node
existing_item.parent = None
break
expand_node.parent = instantiated_branch
return instantiated_branch
Expand Down Expand Up @@ -828,7 +831,6 @@ def render_subtree(
def merge_elem(base, overlay_element):
r = Resolver()
element_name = "/" + overlay_element.qualified_name("/")

if not VSSNode.node_exists(base, element_name):
# The node in the overlay does not exist, so we connect it
# print(f"Not exists {overlay_element.qualified_name()} does not exist, creating.")
Expand All @@ -843,6 +845,7 @@ def merge_elem(base, overlay_element):
other_node: VSSNode = r.get(base, element_name)
try:
other_node.merge(overlay_element)

except ImpossibleMergeException as e:
logging.error(f"Merging impossible: {e}")
sys.exit(-1)
Expand Down

0 comments on commit b654d05

Please sign in to comment.