提交 a455c6a2 编写于 作者: R Rudá Moura

avocado.core.tree: Adopt path_parent() from avocad.multiplexer.

Adopt function path_parent() from the module avocado.multiplexer.
We will need this when we move the filtering to the level of
the tree.
Signed-off-by: NRudá Moura <rmoura@redhat.com>
上级 622aa212
......@@ -241,3 +241,15 @@ def create_from_ordered_data(data, tree=None, root=None, name=''):
def create_from_yaml(input_yaml):
data = read_ordered_yaml(input_yaml)
return create_from_ordered_data(data)
def path_parent(path):
"""
From a given path, return its parent path.
:param path: the node path as string.
:return: the parent path as string.
"""
parent = path.rpartition('/')[0]
if parent == '':
return ''
return parent
......@@ -24,19 +24,6 @@ import collections
from avocado.core import tree
def path_parent(path):
"""
From a given path, return its parent path.
:param path: the node path as string.
:return: the parent path as string.
"""
parent = path.rpartition('/')[0]
if parent == '':
return ''
return parent
def any_sibling(*nodes):
"""
Check if there is any sibling.
......@@ -74,7 +61,7 @@ def filter_only(keys, items):
return True
# siblings and their children, filter them out
if item.parent.path.startswith(path_parent(key)):
if item.parent.path.startswith(tree.path_parent(key)):
ret = False
continue
......@@ -102,7 +89,7 @@ def filter_out(keys, items):
return False
# sibling and its children, let them in
if item.path.startswith(path_parent(key)):
if item.path.startswith(tree.path_parent(key)):
continue
# everything else should get in
......
......@@ -25,19 +25,6 @@ f_only = []
f_out = []
class TestPathParent(unittest.TestCase):
def test_empty_string(self):
self.assertEqual(path_parent(''), '')
def test_on_root(self):
self.assertEqual(path_parent('/'), '')
def test_direct_parent(self):
self.assertEqual(path_parent('/os/linux'), '/os')
def test_false_direct_parent(self):
self.assertNotEqual(path_parent('/os/linux'), '/')
class TestAnySibling(unittest.TestCase):
......
......@@ -133,5 +133,20 @@ class TestTreeNode(unittest.TestCase):
self.assertNotIn(n, self.treenode.children)
class TestPathParent(unittest.TestCase):
def test_empty_string(self):
self.assertEqual(path_parent(''), '')
def test_on_root(self):
self.assertEqual(path_parent('/'), '')
def test_direct_parent(self):
self.assertEqual(path_parent('/os/linux'), '/os')
def test_false_direct_parent(self):
self.assertNotEqual(path_parent('/os/linux'), '/')
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册