def test_Depth_NoLoops(self): grandParent = KeyedNode("grand pa") parent = KeyedNode("pa") child = KeyedNode("me") child.set_parent(parent) parent.set_parent(grandParent) self.assertEqual(child.get_depth(), 2) self.assertEqual(parent.get_depth(), 1) self.assertEqual(grandParent.get_depth(), 0)
def test_Depth_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_depth()) self.assertRaises(TreeHasLoop, lambda: parent.get_depth()) self.assertRaises(TreeHasLoop, lambda: grandParent.get_depth())