[Avocado-devel] TreeNode constructor parent parameter

Cleber Rosa crosa at redhat.com
Wed Nov 9 03:36:56 UTC 2016


Lukáš,

While reviewing your PR (mux-separation3), I came across the fact that
the "parent" parameter of TreeNode doesn't do what *I* expected it to
do. That is, the following test code fails:

import unittest

from avocado.core import tree

class ParentTest(unittest.TestCase):

    def test_parent_parameter(self):
        parent = tree.TreeNode(name='parent')
        child = tree.TreeNode(name='child', parent=parent)
        grandchild = tree.TreeNode(name='grandchild', parent=child)
        self.assertIn(child, parent.children)
        self.assertIn(grandchild, child.children)


But it would work with this simple change:


diff --git a/avocado/core/tree.py b/avocado/core/tree.py
index 27d30f0..2fb3e11 100644
--- a/avocado/core/tree.py
+++ b/avocado/core/tree.py
@@ -69,6 +69,8 @@ class TreeNode(object):
             children = []
         self.name = name
         self.value = value
+        if parent is not None:
+            parent.add_child(self)
         self.parent = parent
         self.children = []
         self.ctrl = []


This is similar to what is already done with "children", and I have the
feeling that both should behave similarly.

Does it make sense?

-- 
Cleber Rosa
[ Sr Software Engineer - Virtualization Team - Red Hat ]
[ Avocado Test Framework - avocado-framework.github.io ]

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/avocado-devel/attachments/20161109/d52ab707/attachment.sig>


More information about the Avocado-devel mailing list