Skip to content

Commit

Permalink
Add directive is-leaf to force selecting node
Browse files Browse the repository at this point in the history
Expected usage with virtual tests while keeping the parent
test as well

Fix: #221
  • Loading branch information
lukaszachy committed Feb 28, 2024
1 parent 29190c7 commit 543e52a
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 5 deletions.
8 changes: 8 additions & 0 deletions docs/features.rst
Expand Up @@ -194,6 +194,14 @@ The key content attributes are not supposed to be hard-coded in
the Flexible Metadata Format but freely configurable. Multiple key
content attributes (e.g. script & backend) could be used as well.

Sometimes it is necessary to select node from the metadata tree
even though it is not leaf. For example, when virtual tests are
created from a parent test but one wants to keep the parent available
as a test as well. To do so, one can set fhe following directive::

/:
is-leaf: true


.. _virtual:

Expand Down
12 changes: 7 additions & 5 deletions fmf/base.py
Expand Up @@ -250,10 +250,12 @@ def check(value, type_, name=None):
for key, value in directives.items():
if key == "inherit":
check(value, bool, name="inherit")
continue
# No other directive supported
raise fmf.utils.FormatError(
f"Unknown fmf directive '{key}' in '{self.name}'.")
elif key == "is-leaf":
check(value, bool, name="is-leaf")
else:
# No other directive supported
raise fmf.utils.FormatError(
f"Unknown fmf directive '{key}' in '{self.name}'.")

# Everything ok, store the directives
self._directives.update(directives)
Expand Down Expand Up @@ -572,7 +574,7 @@ def grow(self, path):

def climb(self, whole=False):
""" Climb through the tree (iterate leaf/all nodes) """
if whole or not self.children:
if whole or not self.children or self._directives.get("is-leaf"):
yield self
for name, child in self.children.items():
for node in child.climb(whole):
Expand Down
1 change: 1 addition & 0 deletions tests/core/is-leaf/data/.fmf/version
@@ -0,0 +1 @@
1
Empty file.
3 changes: 3 additions & 0 deletions tests/core/is-leaf/data/foo/main.fmf
@@ -0,0 +1,3 @@
/:
is-leaf: true
test: echo
7 changes: 7 additions & 0 deletions tests/core/is-leaf/main.fmf
@@ -0,0 +1,7 @@
summary: Verify functionality of the `is-leaf` directive
description:
Sometimes the node should stay reported as a object
even though it has child nodes. Using this directive
allows it. Real life example is to keep "/test" available
after virtual tests "/test/virtual_foo" and "test/virtual_bar"
are created.
14 changes: 14 additions & 0 deletions tests/core/is-leaf/test.sh
@@ -0,0 +1,14 @@
#!/bin/bash
. /usr/share/beakerlib/beakerlib.sh || exit 1

rlJournalStart
rlPhaseStartTest
rlRun "pushd data"

rlRun -s "fmf ls"
rlAssertGrep "^/foo$" $rlRun_LOG
rlAssertGrep "^/foo/child$" $rlRun_LOG

rlRun "popd"
rlPhaseEnd
rlJournalEnd

0 comments on commit 543e52a

Please sign in to comment.