def test_split(self): """Test splitting into subgraphs. """ foo = Foo() bar = Bar() idfoo = id(foo) idbar = id(bar) idfd = id(foo.__dict__) idbd = id(bar.__dict__) foo.next = bar bar.prev = foo l = [] l.append(l) idl = id(l) del foo del bar del l gb = GarbageGraph() subs = list(gb.split()) self.assertEqual(len(subs), 2) fbg = [x for x in subs if x.count == 4][0] lig = [x for x in subs if x.count == 1][0] self.assert_(isinstance(fbg, GarbageGraph)) self.assert_(isinstance(lig, GarbageGraph)) self.assertEqual(len(fbg.edges), 4, fbg.edges) self.assertEqual(len(lig.edges), 1, lig.edges) self.assert_(_Edge(idl, idl, '') in lig.edges, lig.edges) self.assert_(_Edge(idfoo, idfd, '__dict__') in fbg.edges, fbg.edges) self.assert_(_Edge(idfd, idbar, 'next') in fbg.edges, fbg.edges) self.assert_(_Edge(idbar, idbd, '__dict__') in fbg.edges, fbg.edges) self.assert_(_Edge(idbd, idfoo, 'prev') in fbg.edges, fbg.edges)
def test_edges_new(self): """Test referent identification for new-style classes. """ foo = FooNew() bar = BarNew() idfoo = id(foo) idfd = id(foo.__dict__) idbar = id(bar) idbd = id(bar.__dict__) foo.next = bar bar.prev = foo del foo del bar gb = GarbageGraph() self.assert_(_Edge(idfoo, idfd, '__dict__') in gb.edges, gb.edges) self.assert_(_Edge(idfd, idbar, 'next') in gb.edges, gb.edges) self.assert_(_Edge(idbar, idbd, '__dict__') in gb.edges, gb.edges) self.assert_(_Edge(idbd, idfoo, 'prev') in gb.edges, gb.edges)