def test_Ancestory_NoLoops(self): grandParent = KeyedNode("grand pa") parent = KeyedNode("pa") child = KeyedNode("me") child.set_parent(parent) parent.set_parent(grandParent) self.assertEqual(child.get_ancestry(), [parent, grandParent]) self.assertEqual(parent.get_ancestry(), [grandParent]) self.assertEqual(grandParent.get_ancestry(), [])
def test_Ancestory_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_ancestry()) self.assertRaises(TreeHasLoop, lambda: parent.get_ancestry()) self.assertRaises(TreeHasLoop, lambda: grandParent.get_ancestry())