Example #1
0
    def test_gc(self):
        """refcount agnostic check that contained objects are freed"""
        def d(capsule, parent):
            return r[0]

        class Obj(object):
            pass

        c = Obj()
        p = Obj()
        r = [Obj()]
        weak_c = weakref.ref(c)
        weak_p = weakref.ref(p)
        weak_r0 = weakref.ref(r[0])
        weak_d = weakref.ref(d)
        v = View(c, p, d)
        weak_v = weakref.ref(v)
        del c, p, d
        self.assert_(weak_c() is not None)
        self.assert_(weak_p() is not None)
        self.assert_(weak_d() is not None)
        del v
        self.assert_(weak_v() is None)
        self.assert_(weak_c() is None)
        self.assert_(weak_p() is None)
        self.assert_(weak_d() is None)
        self.assert_(weak_r0() is not None)
        del r[0]
        self.assert_(weak_r0() is None)
Example #2
0
    def test_destructor(self):
        def d(capsule, parent):
            success.append(capsule is c)
            success.append(parent is None)

        success = []
        c = []
        view_id = id(View(c, destructor=d))
        self.assert_(success)
        self.assert_(success[0])
        self.assert_(success[1])
Example #3
0
 def __repr__(self):
     return "*%s*" % (View.__repr__(self), )
Example #4
0
 def test_repr(self):
     z = 0
     cname = re.findall(r"'([^']+)'", repr(View))[0]
     oname, ovalue = re.findall(r"<([^)]+)\(([^)]+)\)>", repr(View(0)))[0]
     self.assertEqual(oname, cname)
     self.assertEqual(id(z), int(ovalue, 16))
Example #5
0
 def test_weakref(self):
     v = View([])
     weak_v = weakref.ref(v)
     self.assert_(weak_v() is v)
     del v
     self.assert_(weak_v() is None)
Example #6
0
 def test_parent_property(self):
     c = []
     p = []
     v = View(c, p)
     self.assert_(v.parent is p)
Example #7
0
 def test___array_struct___property(self):
     c = []
     v = View(c)
     self.assert_(v.__array_struct__ is c)
Example #8
0
 def __repr__(self):
     return "*%s*" % (View.__repr__(self),)