Skip to content

Commit

Permalink
special no inheritance mark
Browse files Browse the repository at this point in the history
  • Loading branch information
jscotka committed Apr 6, 2022
1 parent 1cbc082 commit 53a7a54
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/no_inherit/.fmf/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
2 changes: 2 additions & 0 deletions examples/no_inherit/a/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/inherited:
special!: 2
6 changes: 6 additions & 0 deletions examples/no_inherit/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
special!: 1
x: X
/a:
b: b
x!: abc
/inherited:
10 changes: 8 additions & 2 deletions fmf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,14 @@ def merge(self, parent=None):
if parent is None:
return
self.sources = parent.sources + self.sources
# Merge child data with parent data
data = copy.deepcopy(parent.data)
data = {}
# Merge child data with parent da
for key, value in parent.data.items():
# avoid to copy data if marked as stop inheritance
if not key.endswith('!'):
print(f"no inherit {value}")
data[key] = copy.deepcopy(value)

self._merge_special(data, self.data)
self.data = data

Expand Down
24 changes: 24 additions & 0 deletions tests/unit/test_no_inheritance_mark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os
import unittest

import fmf

# Prepare path to examples
PATH = os.path.dirname(os.path.realpath(__file__))
EXAMPLES = PATH + "/../../examples/"


class TestNoInheritance(unittest.TestCase):
""" Verify storing modifed data to disk """

def setUp(self):
self.path = EXAMPLES + "no_inherit"
self.tree = fmf.Tree(self.path)

def test(self):
root_item = self.tree.find('/')
a_item = self.tree.find('/a')
inherite_item = self.tree.find('/a/inherited')
self.assertIn("special!", root_item.data)
self.assertIn("special!", inherite_item.data)
self.assertNotIn("special!", a_item.data)

0 comments on commit 53a7a54

Please sign in to comment.