def test_circular2(self): """ Verify that a circular dependency among 2 objects is detected. """ o1 = Identity() o2 = Identity() o1.depends_on = ["o2"] o2.depends_on = ["o1"] o1.o2 = o2 o2.o1 = o1 with self.assertRaises(RuntimeError): get_owners(o1)
def test_depth_2(self): """ Check cases in which the original object depends on another, which depends on another. """ o1 = Identity() o2 = Identity() o3 = object() o1.depends_on = ["o2"] o2.depends_on = ["o3"] o1.o2 = o2 o2.o3 = o3 self.assertEqual(get_owners(o1), [o1, o2, o3])
def test_depth_1(self): """ Check cases in which the original object depends on 1 or more others. """ o1 = Identity() o2 = Identity() o1.o2 = o2 o1.depends_on = ["o2"] self.assertEqual(get_owners(o1), [o1, o2]) o3 = object() o1.depends_on = ["o3", "o2"] o1.o3 = o3 self.assertEqual(get_owners(o1), [o1, o3, o2])
def test_circular4(self): """ Verify that a circular dependency among 4 objects is detected. """ o1 = Identity() o2 = Identity() o3 = Identity() o4 = Identity() o1.depends_on = ["o2"] o2.depends_on = ["o3"] o3.depends_on = ["o4"] o4.depends_on = ["o1"] o1.o2 = o2 o2.o3 = o3 o3.o4 = o4 o4.o1 = o1 with self.assertRaises(RuntimeError): get_owners(o1)