Commit 5b2fc00e authored by jlaura's avatar jlaura Committed by Jesse Mapel
Browse files

Fixes parent/child warning in test suite (#169)

parent e99e3d25
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -41,10 +41,13 @@ class FrameNode():
        self.children = []
        self.id = id
        if parent is not None:
            self._parent = parent
            self.parent = parent
        if rotation is not None:
            self.rotation = rotation

    def __repr__(self):
        return f'ID:{self.id}\nChildren:{self.children}'

    def __del__(self):
        """
        Custom deletor for a FrameNode. The child node is always responsible
@@ -72,7 +75,7 @@ class FrameNode():
        of the old parent and adds it to the children of the new parent.
        """
        if self.parent is not None:
            self.parent.children.remove(self)
            self._parent.children.remove(self)

        new_parent.children.append(self)
        self._parent = new_parent
+10 −2
Original line number Diff line number Diff line
@@ -4,8 +4,8 @@ import numpy as np
from ale.rotation import ConstantRotation
from ale.transformation import FrameNode

@pytest.fixture
def frame_tree():
@pytest.fixture(scope='function')
def frame_tree(request):
    """
    Test frame tree structure:

@@ -34,6 +34,14 @@ def frame_tree():
    ]
    return (nodes, rotations)

def test_del_node(frame_tree):
    nodes, _ = frame_tree
    node3 = nodes[3]
    node2 = nodes[2]
    del node3
    
    assert len(node2.children) == 0

def test_parent_nodes(frame_tree):
    nodes, _ = frame_tree
    root_parents = nodes[0].parent_nodes()