Example #1
0
    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 = gb.split_and_sort()
        self.assertEqual(len(subs), 2)

        self.assertEqual(subs[0].count, 4)
        self.assertEqual(subs[1].count, 1)
        fbg, lig = subs

        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)
Example #2
0
    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 = gb.split_and_sort()
        self.assertEqual(len(subs), 2)

        self.assertEqual(subs[0].count, 4)
        self.assertEqual(subs[1].count, 1)
        fbg, lig = subs

        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)
Example #3
0
    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)
Example #4
0
    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)
Example #5
0
    def test_edges_old(self):
        """Test referent identification for old-style classes.
        """
        foo = Foo()
        bar = Bar()

        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)