Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
e7add1df
Commit
e7add1df
authored
Aug 09, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add some tests for __dealloc__()
parent
d40333a2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
168 additions
and
0 deletions
+168
-0
tests/run/exttype_dealloc.pyx
tests/run/exttype_dealloc.pyx
+168
-0
No files found.
tests/run/exttype_dealloc.pyx
0 → 100644
View file @
e7add1df
# mode: run
# tag: dealloc
import
gc
test_results
=
[]
cdef
void
add_name
(
obj
):
name
=
type
(
obj
).
__name__
.
rsplit
(
'.'
,
1
)[
-
1
]
test_results
.
append
(
name
)
def
find_name
(
exttype
):
name
=
exttype
.
__name__
.
rsplit
(
'.'
,
1
)[
-
1
]
return
test_results
.
count
(
name
)
cdef
class
ExtTypeSimple
:
"""
>>> obj = ExtTypeSimple()
>>> find_name(ExtTypeSimple)
0
>>> obj = None
>>> _ = gc.collect()
>>> find_name(ExtTypeSimple)
1
"""
cdef
int
x
def
__dealloc__
(
self
):
add_name
(
self
)
self
.
x
=
0
class
PySubTypeSimple
(
ExtTypeSimple
):
"""
>>> obj = PySubTypeSimple()
>>> find_name(PySubTypeSimple)
0
>>> obj = None
>>> _ = gc.collect()
>>> find_name(PySubTypeSimple)
1
"""
class
PySubTypeDel
(
ExtTypeSimple
):
"""
>>> obj = PySubTypeDel()
>>> find_name(PySubTypeDel)
0
>>> obj = None
>>> _ = gc.collect()
>>> find_name(PySubTypeDel)
2
"""
def
__del__
(
self
):
add_name
(
self
)
cdef
class
ExtSubTypeObjAttr
(
ExtTypeSimple
):
"""
>>> obj = ExtSubTypeObjAttr()
>>> find_name(ExtSubTypeObjAttr)
0
>>> obj = None
>>> _ = gc.collect()
# both this type and the base class add the same name
>>> find_name(ExtSubTypeObjAttr)
2
"""
cdef
object
attr
def
__dealloc__
(
self
):
add_name
(
self
)
self
.
x
=
1
cdef
class
ExtTypeRaise
:
"""
>>> obj = ExtTypeRaise()
>>> find_name(ExtTypeRaise)
0
>>> obj = None
>>> _ = gc.collect()
>>> find_name(ExtTypeRaise)
1
"""
def
__dealloc__
(
self
):
add_name
(
self
)
raise
RuntimeError
(
"HUHU !"
)
class
PySubTypeRaise
(
ExtTypeRaise
):
"""
>>> obj = PySubTypeRaise()
>>> obj.ref = obj
>>> find_name(PySubTypeRaise)
0
>>> obj = None
>>> _ = gc.collect()
>>> find_name(PySubTypeRaise)
1
"""
cdef
class
ExtTypeRefCycle
:
"""
>>> obj = ExtTypeRefCycle()
>>> obj.ref = obj
>>> find_name(ExtTypeRefCycle)
0
>>> obj = None
>>> _ = gc.collect()
>>> find_name(ExtTypeRefCycle)
1
"""
cdef
public
object
ref
cdef
int
x
def
__dealloc__
(
self
):
add_name
(
self
)
self
.
x
=
1
class
PySubTypeRefCycleDel
(
ExtTypeRefCycle
):
"""
>>> obj = PySubTypeRefCycleDel()
>>> obj.ref = obj
>>> find_name(PySubTypeRefCycleDel)
0
>>> obj = None
>>> _ = gc.collect()
# no guarantees here ...
"""
def
__del__
(
self
):
add_name
(
self
)
cdef
class
ExtTypeRefCycleRaise
:
"""
>>> obj = ExtTypeRefCycleRaise()
>>> obj.ref = obj
>>> find_name(ExtTypeRefCycleRaise)
0
>>> obj = None
>>> _ = gc.collect()
>>> find_name(ExtTypeRefCycleRaise)
1
"""
cdef
public
object
ref
def
__dealloc__
(
self
):
add_name
(
self
)
raise
RuntimeError
(
"Cleaning up !"
)
class
PySubTypeRefCycleRaise
(
ExtTypeRefCycleRaise
):
"""
>>> obj = PySubTypeRefCycleRaise()
>>> obj.ref = obj
>>> find_name(PySubTypeRefCycleRaise)
0
>>> obj = None
>>> _ = gc.collect()
>>> find_name(PySubTypeRefCycleRaise)
1
"""
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment