Пример #1
0
 def testSexp_sexp_set(self):
     x = rinterface.IntSexpVector([1, 2, 3])
     x_s = x.__sexp__
     x_rid = x.rid
     # The Python reference count of the capsule is incremented,
     # not the rpy2 reference count
     self.assertEqual(1, x.__sexp_refcount__)
     y = rinterface.IntSexpVector([4, 5, 6])
     y_count = y.__sexp_refcount__
     y_rid = y.rid
     self.assertEqual(1, y_count)
     self.assertTrue(
         x_rid in [elt[0] for elt in rinterface.protected_rids()])
     x.__sexp__ = y.__sexp__
     self.assertFalse(
         x_rid in [elt[0] for elt in rinterface.protected_rids()])
     self.assertEqual(x.rid, y.rid)
     self.assertEqual(y_rid, y.rid)
     # now both x and y point to the same capsule, making
     # the rpy2 reference count to 2
     self.assertEqual(x.__sexp_refcount__, y.__sexp_refcount__)
     self.assertEqual(y_count + 1, x.__sexp_refcount__)
     del (x)
     self.assertTrue(
         y_rid in [elt[0] for elt in rinterface.protected_rids()])
     del (y)
     self.assertFalse(
         y_rid in [elt[0] for elt in rinterface.protected_rids()])
Пример #2
0
 def testRpyMemory(self):
     x = rinterface.SexpVector(range(10), rinterface.INTSXP)
     y = rinterface.SexpVector(range(10), rinterface.INTSXP)
     x_rid = x.rid
     self.assertTrue(x_rid in set(z[0] for z in rinterface.protected_rids()))
     del(x)
     gc.collect(); gc.collect()
     self.assertFalse(x_rid in set(z[0] for z in rinterface.protected_rids()))
Пример #3
0
 def testRpyMemory(self):
     x = rinterface.SexpVector(range(10), rinterface.INTSXP)
     y = rinterface.SexpVector(range(10), rinterface.INTSXP)
     x_rid = x.rid
     self.assertTrue(x_rid in set(z[0]
                                  for z in rinterface.protected_rids()))
     del (x)
     gc.collect()
     gc.collect()
     self.assertFalse(x_rid in set(z[0]
                                   for z in rinterface.protected_rids()))
Пример #4
0
 def testSexp_sexp_UniqueCapsule(self):
     sexp = rinterface.IntSexpVector([1,2,3])
     sexp_count = sexp.__sexp_refcount__
     cobj = sexp.__sexp__
     # check that no increase in the refcount: the capsule is unique
     self.assertEqual(sexp_count, sexp.__sexp_refcount__)
     self.assertEqual(sexp_count, 
                      dict(rinterface.protected_rids())[sexp.rid])
     del(cobj)
     gc.collect()
     self.assertEqual(sexp_count, sexp.__sexp_refcount__)
     self.assertEqual(sexp_count, 
                      dict(rinterface.protected_rids())[sexp.rid])
     sexp_rid = sexp.rid
     del(sexp)
     gc.collect()
     self.assertFalse(sexp_rid in dict(rinterface.protected_rids()))
Пример #5
0
 def testSexp_sexp_UniqueCapsule(self):
     sexp = rinterface.IntSexpVector([1, 2, 3])
     sexp_count = sexp.__sexp_refcount__
     cobj = sexp.__sexp__
     # check that no increase in the refcount: the capsule is unique
     self.assertEqual(sexp_count, sexp.__sexp_refcount__)
     self.assertEqual(sexp_count,
                      dict(rinterface.protected_rids())[sexp.rid])
     del (cobj)
     gc.collect()
     self.assertEqual(sexp_count, sexp.__sexp_refcount__)
     self.assertEqual(sexp_count,
                      dict(rinterface.protected_rids())[sexp.rid])
     sexp_rid = sexp.rid
     del (sexp)
     gc.collect()
     self.assertFalse(sexp_rid in dict(rinterface.protected_rids()))
Пример #6
0
 def testSexp_sexp_set(self):
     x = rinterface.IntSexpVector([1,2,3])
     x_s = x.__sexp__
     x_rid = x.rid
     # The Python reference count of the capsule is incremented,
     # not the rpy2 reference count
     self.assertEqual(1, x.__sexp_refcount__)
     y = rinterface.IntSexpVector([4,5,6])
     y_count = y.__sexp_refcount__
     y_rid = y.rid
     self.assertEqual(1, y_count)
     self.assertTrue(x_rid in [elt[0] for elt in rinterface.protected_rids()])
     x.__sexp__ = y.__sexp__
     self.assertFalse(x_rid in [elt[0] for elt in rinterface.protected_rids()])
     self.assertEqual(x.rid, y.rid)
     self.assertEqual(y_rid, y.rid)
     # now both x and y point to the same capsule, making
     # the rpy2 reference count to 2
     self.assertEqual(x.__sexp_refcount__, y.__sexp_refcount__)
     self.assertEqual(y_count+1, x.__sexp_refcount__)
     del(x)
     self.assertTrue(y_rid in [elt[0] for elt in rinterface.protected_rids()])
     del(y)
     self.assertFalse(y_rid in [elt[0] for elt in rinterface.protected_rids()])