Example #1
0
    def test_varray_smart_pointer_in_cpp(self):
        """...Test C++ reference counter
        """
        vcc = test.VarrayContainer()
        self.assertEqual(vcc.nRef(), 0)
        vcc.initVarray()
        self.assertEqual(vcc.nRef(), 1)
        cu1 = test.VarrayUser()
        cu1.setArray(vcc)
        self.assertEqual(vcc.nRef(), 2)
        cu1.setArray(vcc)
        self.assertEqual(vcc.nRef(), 2)
        cu2 = test.VarrayUser()
        cu2.setArray(vcc)
        self.assertEqual(vcc.nRef(), 3)
        del cu1
        self.assertEqual(vcc.nRef(), 2)
        cu3 = test.VarrayUser()
        cu3.setArray(vcc)
        self.assertEqual(vcc.nRef(), 3)
        del cu3, cu2
        self.assertEqual(vcc.nRef(), 1)
        # we cannot check it will go to 0 after vcc deletion in Python

        cu4 = test.VarrayUser()
        cu4.setArray(vcc)
        self.assertEqual(vcc.nRef(), 2)
        del vcc
        self.assertEqual(cu4.nRef(), 1)
        # we cannot check it will go to 0 after cu4 deletion in Python
        del cu4
Example #2
0
    def test_varray_smart_pointer_deletion2(self):
        """...Test that base is deleted after a double assignment in Python
        """
        vcc = test.VarrayContainer()
        vcc.initVarray()

        a = vcc.varrayPtr
        b = vcc.varrayPtr
        r = weakref.ref(b)
        del a, vcc, b
        self.assertIsNone(r())
Example #3
0
 def test_varray_share_same_support(self):
     """...Test that modifications on Varray of in Python affect the same
     support
     """
     vcc = test.VarrayContainer()
     vcc.initVarray()
     # Now mix with some Python
     a = vcc.varrayPtr
     a[0] = 99.0
     self.assertEqual(vcc.varrayPtr[0], 99.0)
     vcc.varrayPtr[1] = 999.0
     self.assertEqual(a[1], 999.0)
Example #4
0
 def test_varray_smart_pointer_deletion1(self):
     """...Test that varray is still alive after deletion in Python
     """
     vcc = test.VarrayContainer()
     vcc.initVarray()
     # Now mix with some Python
     a = vcc.varrayPtr
     # This does not increment C++ reference counter
     self.assertEqual(vcc.nRef(), 1)
     # Get a weak ref of the array
     r = weakref.ref(a)
     del a
     np.testing.assert_array_almost_equal(r(), vcc.varrayPtr)
     del vcc
     self.assertIsNone(r())
Example #5
0
    def test_varray_smart_pointer_deletion3(self):
        """...Test that base is deleted after a double assignment in Python
        """
        vcc = test.VarrayContainer()
        vcc.initVarray()
        # Now mix with some Python
        a = vcc.varrayPtr
        a_sum = np.sum(a)
        # This does not increment C++ reference counter
        self.assertEqual(vcc.nRef(), 1)

        # Get a weak ref of the array
        r = weakref.ref(vcc.varrayPtr)

        del vcc
        np.testing.assert_array_almost_equal(a_sum, np.sum(a))

        self.assertIsNone(r())
        del a