def test_RootNode_NoLoops(self): grandParent = KeyedNode("grand pa") parent = KeyedNode("pa") child = KeyedNode("me") child.set_parent(parent) parent.set_parent(grandParent) self.assertEqual(child.get_root_node(), grandParent) self.assertEqual(parent.get_root_node(), grandParent) self.assertEqual(grandParent.get_root_node(), grandParent)
def test_RootNode_LoopException(self): grandParent = KeyedNode("grand pa") parent = KeyedNode("pa") child = KeyedNode("me") child.set_parent(parent) parent.set_parent(grandParent) grandParent.set_parent(child) self.assertRaises(TreeHasLoop, lambda: child.get_root_node()) self.assertRaises(TreeHasLoop, lambda: parent.get_root_node()) self.assertRaises(TreeHasLoop, lambda: grandParent.get_root_node())