diff --git a/avocado/core/tree.py b/avocado/core/tree.py index 445b1fb5892e402890b3008ef06403777bcc6c5d..9c9f4c622ad6335a463a5d4629826005840de71c 100644 --- a/avocado/core/tree.py +++ b/avocado/core/tree.py @@ -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 diff --git a/selftests/all/unit/avocado/tree_unittest.py b/selftests/all/unit/avocado/tree_unittest.py index 47cfa189e369e17c4017008d16a5aa5bb6e0ac27..a533c2bd1e94a54156d5d3583d280e683b51c5eb 100644 --- a/selftests/all/unit/avocado/tree_unittest.py +++ b/selftests/all/unit/avocado/tree_unittest.py @@ -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')