提交 9d20e6bf 编写于 作者: L Lukáš Doktor

avocado.core.tree: Return correct path for the root node

Without this patch the root node path is ''. With this patch it returns
path-like '/'.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 445a0bcd
......@@ -209,6 +209,8 @@ class TreeNode(object):
def get_path(self, sep='/'):
""" Get node path """
if not self.parent:
return sep + str(self.name)
path = [str(self.name)]
for node in self.iter_parents():
path.append(str(node.name))
......@@ -540,6 +542,8 @@ def path_parent(path):
:return: the parent path as string.
"""
parent = path.rpartition('/')[0]
if not parent:
return '/'
return parent
......
......@@ -190,10 +190,10 @@ class TestTree(unittest.TestCase):
class TestPathParent(unittest.TestCase):
def test_empty_string(self):
self.assertEqual(tree.path_parent(''), '')
self.assertEqual(tree.path_parent(''), '/')
def test_on_root(self):
self.assertEqual(tree.path_parent('/'), '')
self.assertEqual(tree.path_parent('/'), '/')
def test_direct_parent(self):
self.assertEqual(tree.path_parent('/os/linux'), '/os')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册