Skip to content

Commit fa8a442

Browse files
committed
finish it
1 parent 45d7f98 commit fa8a442

File tree

6 files changed

+52
-13
lines changed

6 files changed

+52
-13
lines changed

fmf/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,6 @@ def __getitem__(self, key):
796796
else:
797797
return self.data[key]
798798

799-
def apply_profile(self, profile: Profile) -> Profile:
800-
pass
799+
def apply_profile(self, profile: Profile) -> None:
800+
profile.apply_rule(self)
801801

fmf/profile.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,28 @@ def __init__(self, rule: dict, name = None):
4747
self.name = name
4848
if "where" not in self._raw_rule.keys():
4949
raise ProfileWithoutWhereStatement
50-
self.where = self._raw_rule["where"]
51-
self.rules = deepcopy(self._raw_rule).pop("where")
50+
self.where = self._raw_rule.pop("where")
51+
self.rules = deepcopy(self._raw_rule)
5252

5353
def _check_if_fmf_node_match(self, node):
54-
context = Context(node.data)
54+
context = Context(**node.data)
5555
return context.matches(self.where)
5656

57-
def apply_rule(self, node):
57+
def _apply_rule(self, node):
58+
5859
if not self._check_if_fmf_node_match(node):
5960
return
6061
for rule in self.rules:
6162
if isinstance(rule, str) and rule.endswith("?"):
6263
rule_clear = rule[:-1]
63-
data = {rule_clear : self.rules["rule"]}
64+
data = {rule_clear : self.rules[rule]}
6465
if rule_clear in node.data:
6566
# do not override if defined
6667
continue
6768
else:
68-
data = {rule: self.rules["rule"]}
69-
node._merge_special(node, data)
69+
data = {rule: self.rules[rule]}
70+
node._merge_special(node.data, data)
71+
72+
def apply_rule(self, node):
73+
for item in node.climb():
74+
self._apply_rule(item)

tests/unit/data/profile/profile_file.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plan1_definition:
2-
where: execute is defined and discovery is defined
2+
where: execute is defined cc and discover is defined
33
# append to prepare phase
44
prepare+:
55
name: some name
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/base:
2+
summary: test plans
3+
execute:
4+
how: tmt
5+
provision:
6+
how: minute
7+
/plan0:
8+
discover:
9+
how: fmf
10+
/plan1:
11+
discover:
12+
how: shell
13+
report:
14+
how: polarion
15+
prepare:
16+
name: some name
17+
how: shell
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test: test1.sh
2+
summary: hello

tests/unit/test_profile.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
PROFILE_PATH = Path(__file__).parent / "data" / "profile"
1010
PROFILE = PROFILE_PATH / "profile_file.yaml"
11-
FMF_TREE = Tree(PROFILE_PATH / "tree")
12-
class Profile_Load(TestCase):
11+
12+
class ProfileLoad(TestCase):
1313
def setUp(self) -> None:
1414
with PROFILE.open("r") as profile_file:
1515
self.profile_data = yaml.safe_load(profile_file)
@@ -18,4 +18,19 @@ def test_load(self):
1818
profiles = []
1919
for k, v in self.profile_data.items():
2020
profiles.append(Profile(v, name=k))
21-
print(profiles)
21+
22+
23+
class ProfileApply(TestCase):
24+
def setUp(self) -> None:
25+
with PROFILE.open("r") as profile_file:
26+
self.profile_data = yaml.safe_load(profile_file)
27+
self.profiles = []
28+
for k, v in self.profile_data.items():
29+
self.profiles.append(Profile(v, name=k))
30+
self.fmf_tree = Tree(PROFILE_PATH / "tree")
31+
32+
def test_apply_to_test(self):
33+
for profile in self.profiles:
34+
self.fmf_tree.apply_profile(profile)
35+
for item in self.fmf_tree.climb():
36+
print(item.data)

0 commit comments

Comments
 (0)