[Avocado-devel] TreeNode constructor parent parameter

Lukáš Doktor ldoktor at redhat.com
Wed Nov 9 10:06:35 UTC 2016


Dne 9.11.2016 v 04:36 Cleber Rosa napsal(a):
> 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?
>

It's been a while since I touched this code. I remember it had a purpose 
back then, the children were added, but parent had to be managed 
manually. I don't remember why or whether it was just inherited from the 
original code, but I can try adding it. Please comment it on GH, I'll 
add a commit and we'll see whether it breaks anything.

Lukáš

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


More information about the Avocado-devel mailing list