Skip to content

Commit

Permalink
finish it
Browse files Browse the repository at this point in the history
  • Loading branch information
jscotka committed Jul 26, 2023
1 parent 45d7f98 commit fa8a442
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 13 deletions.
4 changes: 2 additions & 2 deletions fmf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,6 @@ def __getitem__(self, key):
else:
return self.data[key]

def apply_profile(self, profile: Profile) -> Profile:
pass
def apply_profile(self, profile: Profile) -> None:
profile.apply_rule(self)

19 changes: 12 additions & 7 deletions fmf/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,28 @@ def __init__(self, rule: dict, name = None):
self.name = name
if "where" not in self._raw_rule.keys():
raise ProfileWithoutWhereStatement
self.where = self._raw_rule["where"]
self.rules = deepcopy(self._raw_rule).pop("where")
self.where = self._raw_rule.pop("where")
self.rules = deepcopy(self._raw_rule)

def _check_if_fmf_node_match(self, node):
context = Context(node.data)
context = Context(**node.data)
return context.matches(self.where)

def apply_rule(self, node):
def _apply_rule(self, node):

if not self._check_if_fmf_node_match(node):
return
for rule in self.rules:
if isinstance(rule, str) and rule.endswith("?"):
rule_clear = rule[:-1]
data = {rule_clear : self.rules["rule"]}
data = {rule_clear : self.rules[rule]}
if rule_clear in node.data:
# do not override if defined
continue
else:
data = {rule: self.rules["rule"]}
node._merge_special(node, data)
data = {rule: self.rules[rule]}
node._merge_special(node.data, data)

def apply_rule(self, node):
for item in node.climb():
self._apply_rule(item)
2 changes: 1 addition & 1 deletion tests/unit/data/profile/profile_file.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plan1_definition:
where: execute is defined and discovery is defined
where: execute is defined cc and discover is defined
# append to prepare phase
prepare+:
name: some name
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/data/profile/tree/plan.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/base:
summary: test plans
execute:
how: tmt
provision:
how: minute
/plan0:
discover:
how: fmf
/plan1:
discover:
how: shell
report:
how: polarion
prepare:
name: some name
how: shell
2 changes: 2 additions & 0 deletions tests/unit/data/profile/tree/test.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test: test1.sh
summary: hello
21 changes: 18 additions & 3 deletions tests/unit/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

PROFILE_PATH = Path(__file__).parent / "data" / "profile"
PROFILE = PROFILE_PATH / "profile_file.yaml"
FMF_TREE = Tree(PROFILE_PATH / "tree")
class Profile_Load(TestCase):

class ProfileLoad(TestCase):
def setUp(self) -> None:
with PROFILE.open("r") as profile_file:
self.profile_data = yaml.safe_load(profile_file)
Expand All @@ -18,4 +18,19 @@ def test_load(self):
profiles = []
for k, v in self.profile_data.items():
profiles.append(Profile(v, name=k))
print(profiles)


class ProfileApply(TestCase):
def setUp(self) -> None:
with PROFILE.open("r") as profile_file:
self.profile_data = yaml.safe_load(profile_file)
self.profiles = []
for k, v in self.profile_data.items():
self.profiles.append(Profile(v, name=k))
self.fmf_tree = Tree(PROFILE_PATH / "tree")

def test_apply_to_test(self):
for profile in self.profiles:
self.fmf_tree.apply_profile(profile)
for item in self.fmf_tree.climb():
print(item.data)

0 comments on commit fa8a442

Please sign in to comment.