Skip to content

Commit

Permalink
Strip merge suffix in root node as well
Browse files Browse the repository at this point in the history
Otherwise `key+` defined in root node or node with broken
inheritance will be called `key+` instead of `key`.
All other nodes already strip the merge suffix

Fix: #277
  • Loading branch information
lukaszachy committed Jan 28, 2025
1 parent 3c1b7c1 commit afecbb3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
3 changes: 3 additions & 0 deletions examples/merge/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Merge suffix can be used and will be stripped
environment+:
SOME: value
6 changes: 6 additions & 0 deletions examples/merge/stray.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/:
inherit: false

# Merge suffix will be stripped
environment+:
NOTHING: here
16 changes: 7 additions & 9 deletions fmf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,17 +372,15 @@ def init(path):

def merge(self, parent=None):
""" Merge parent data """
# Check parent, append source files
# Check parent
if parent is None:
parent = self.parent
if parent is None:
return
# Do not inherit when disabled
if self._directives.get("inherit") is False:
return
self.sources = parent.sources + self.sources
# Merge child data with parent data
data = copy.deepcopy(parent.data)
if self._directives.get("inherit") is False or parent is None:
# Nothing to inherit
data = {}
else:
self.sources = parent.sources + self.sources
data = copy.deepcopy(parent.data)
self._merge_special(data, self.data)
self.data = data

Expand Down
8 changes: 8 additions & 0 deletions tests/unit/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ def test_adjust_can_extend(self):
assert child.data['environment']['FOO'] == "bar"
assert child.data['environment']['BAR'] == "baz"

def test_node_without_parent_strips_merge_suffix(self):
""" Merge suffix is stripped in the top node as well """
tree = Tree(EXAMPLES + 'merge')
stray_child = tree.find('/stray')
assert 'environment' in stray_child.data
child = tree.find('/parent/reduced')
assert 'environment' in child.data

def test_deep_hierarchy(self):
""" Deep hierarchy on one line """
deep = Tree(EXAMPLES + "deep")
Expand Down

0 comments on commit afecbb3

Please sign in to comment.