Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip merge suffix in root node as well #280

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -378,17 +378,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 @@ -158,6 +158,14 @@ def test_adjust_strips_control_keys(self):
assert 'because' not in child.data
assert 'foo' in child.data

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
Loading