1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
"""
PYTHON setup.py build_ext -i
PYTHON runtests.py
"""
####### runtests.py #######
import gc
from testclasses import *
import baseclasses
def test_has_del():
inst = HasIndirectDel()
inst = None
gc.collect()
assert baseclasses.HasDel_del_called_count
def test_no_del():
inst = NoIndirectDel()
inst = None
gc.collect()
# The test here is that it doesn't crash
test_has_del()
test_no_del()
######## setup.py ########
from setuptools import setup
from Cython.Build import cythonize
setup(ext_modules = cythonize('*.pyx'))
####### baseclasses.pxd ######
cdef class HasDel:
pass
cdef class DoesntHaveDel:
pass
####### baseclasses.pyx ######
HasDel_del_called_count = 0
cdef class HasDel:
def __del__(self):
global HasDel_del_called_count
HasDel_del_called_count += 1
cdef class DoesntHaveDel:
pass
######## testclasses.pyx ######
cimport cython
from baseclasses cimport HasDel, DoesntHaveDel
@cython.final
cdef class HasIndirectDel(HasDel):
pass
@cython.final
cdef class NoIndirectDel(DoesntHaveDel):
# But Cython can't tell that we don't have __del__ until runtime,
# so has to generate code to call it (and not crash!)
pass
|