Beispiel #1
0
    def test_subclass_with_reference_counting(self):
        class Test(foo.Zbr):
            def __init__(self, y):
                super(Test, self).__init__("foo")
                self.y = y
            def get_int(self, x):
                return getattr(self, 'y', 0) + x
                
        while gc.collect():
            pass
        count_before = foo.Zbr.instance_count
        foo.store_zbr(Test(123))
        while gc.collect():
            pass

        ## check that Zbr isn't prematurely deleted
        self.assertEqual(foo.Zbr.instance_count, count_before + 1)

        ## invoke the virtual method and check that it returns the correct value
        value = foo.invoke_zbr(456)
        self.assertEqual(value, 123+456)

        ## now delete the object from the C side..
        foo.delete_stored_zbr()
        while gc.collect():
            pass

        ## check that Zbr was finally deleted
        self.assertEqual(foo.Zbr.instance_count, count_before)
    def test_subclass_with_reference_counting(self):
        class Test(foo.Zbr):
            def __init__(self, y):
                super(Test, self).__init__("foo")
                self.y = y

            def get_int(self, x):
                return getattr(self, 'y', 0) + x

        while gc.collect():
            pass
        count_before = foo.Zbr.instance_count
        foo.store_zbr(Test(123))
        while gc.collect():
            pass

        ## check that Zbr isn't prematurely deleted
        self.assertEqual(foo.Zbr.instance_count, count_before + 1)

        ## invoke the virtual method and check that it returns the correct value
        value = foo.invoke_zbr(456)
        self.assertEqual(value, 123 + 456)

        ## now delete the object from the C side..
        foo.delete_stored_zbr()
        while gc.collect():
            pass

        ## check that Zbr was finally deleted
        self.assertEqual(foo.Zbr.instance_count, count_before)