Skip to content

Commit

Permalink
Adapt the garbage collection tests to run under PyPy. This makes the …
Browse files Browse the repository at this point in the history
…overall test diff smaller and easier to read.
  • Loading branch information
jamadden committed Mar 21, 2015
1 parent 56a8ece commit db7e3eb
Showing 1 changed file with 64 additions and 58 deletions.
122 changes: 64 additions & 58 deletions src/Acquisition/tests.py
Expand Up @@ -354,6 +354,10 @@ def unicode(self):
PY3 = False
py_impl = getattr(platform, 'python_implementation', lambda: None)
PYPY = py_impl() == 'PyPy'
if not hasattr(gc, 'get_threshold'):
# PyPy
gc.get_threshold = lambda: ()
gc.set_threshold = lambda *x: None

import ExtensionClass
import Acquisition
Expand Down Expand Up @@ -1795,66 +1799,68 @@ def showaq(m_self, indent=''):
rval = rval + indent + id + "\n"
return rval

if hasattr(gc, 'get_threshold'):
#CPython implementation detail
def test_Basic_gc():
"""Test to make sure that EC instances participate in GC
def test_Basic_gc():
"""Test to make sure that EC instances participate in GC.
Note that PyPy always reports 0 collected objects even
though we can see its finalizers run.
>>> from ExtensionClass import Base
>>> import gc
>>> thresholds = gc.get_threshold()
>>> gc.set_threshold(0)
>>> from ExtensionClass import Base
>>> import gc
>>> thresholds = gc.get_threshold()
>>> gc.set_threshold(0)
>>> for B in I, E:
... class C1(B):
... pass
...
... class C2(Base):
... def __del__(self):
... print('removed')
...
... a=C1('a')
... a.b = C1('a.b')
... a.b.a = a
... a.b.c = C2()
... ignore = gc.collect()
... del a
... removed = gc.collect()
... print(removed > 0)
removed
True
removed
True
>>> gc.set_threshold(*thresholds)
"""
def test_Wrapper_gc():
"""Test to make sure that EC instances participate in GC
>>> import gc
>>> thresholds = gc.get_threshold()
>>> gc.set_threshold(0)
>>> for B in I, E:
... class C:
... def __del__(self):
... print('removed')
...
... a=B('a')
... a.b = B('b')
... a.a_b = a.b # circ ref through wrapper
... a.b.c = C()
... ignored = gc.collect()
... del a
... removed = gc.collect()
... removed > 0
removed
True
removed
True
>>> gc.set_threshold(*thresholds)
>>> for B in I, E:
... class C1(B):
... pass
...
... class C2(Base):
... def __del__(self):
... print('removed')
...
... a=C1('a')
... a.b = C1('a.b')
... a.b.a = a
... a.b.c = C2()
... ignore = gc.collect()
... del a
... removed = gc.collect()
... print(removed > 0 or PYPY)
removed
True
removed
True
>>> gc.set_threshold(*thresholds)
"""
def test_Wrapper_gc():
"""Test to make sure that EC instances participate in GC.
Note that PyPy always reports 0 collected objects even
though we can see its finalizers run.
>>> import gc
>>> thresholds = gc.get_threshold()
>>> gc.set_threshold(0)
>>> for B in I, E:
... class C:
... def __del__(self):
... print('removed')
...
... a=B('a')
... a.b = B('b')
... a.a_b = a.b # circ ref through wrapper
... a.b.c = C()
... ignored = gc.collect()
... del a
... removed = gc.collect()
... removed > 0 or PYPY
removed
True
removed
True
>>> gc.set_threshold(*thresholds)
"""

Expand Down

0 comments on commit db7e3eb

Please sign in to comment.