pyo3-pytests: cover more tests on PyPy
This commit is contained in:
parent
5f2627aac2
commit
95cb5c6ef1
|
@ -3,22 +3,23 @@ import platform
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pyo3_pytests.objstore import ObjStore
|
from pyo3_pytests.objstore import ObjStore
|
||||||
|
|
||||||
PYPY = platform.python_implementation() == "PyPy"
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(PYPY, reason="PyPy does not have sys.getrefcount")
|
|
||||||
def test_objstore_doesnot_leak_memory():
|
def test_objstore_doesnot_leak_memory():
|
||||||
N = 10000
|
N = 10000
|
||||||
message = b'\\(-"-;) Praying that memory leak would not happen..'
|
message = b'\\(-"-;) Praying that memory leak would not happen..'
|
||||||
before = sys.getrefcount(message)
|
|
||||||
|
# PyPy does not have sys.getrefcount, provide a no-op lambda and don't
|
||||||
|
# check refcount on PyPy
|
||||||
|
getrefcount = getattr(sys, "getrefcount", lambda obj: 0)
|
||||||
|
|
||||||
|
before = getrefcount(message)
|
||||||
store = ObjStore()
|
store = ObjStore()
|
||||||
for _ in range(N):
|
for _ in range(N):
|
||||||
store.push(message)
|
store.push(message)
|
||||||
del store
|
del store
|
||||||
gc.collect()
|
gc.collect()
|
||||||
after = sys.getrefcount(message)
|
after = getrefcount(message)
|
||||||
|
|
||||||
assert after - before == 0
|
assert after - before == 0
|
||||||
|
|
|
@ -2,8 +2,6 @@ import platform
|
||||||
|
|
||||||
from pyo3_pytests.subclassing import Subclassable
|
from pyo3_pytests.subclassing import Subclassable
|
||||||
|
|
||||||
PYPY = platform.python_implementation() == "PyPy"
|
|
||||||
|
|
||||||
|
|
||||||
class SomeSubClass(Subclassable):
|
class SomeSubClass(Subclassable):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -11,7 +9,6 @@ class SomeSubClass(Subclassable):
|
||||||
|
|
||||||
|
|
||||||
def test_subclassing():
|
def test_subclassing():
|
||||||
if not PYPY:
|
a = SomeSubClass()
|
||||||
a = SomeSubClass()
|
assert str(a) == "SomeSubclass"
|
||||||
assert str(a) == "SomeSubclass"
|
assert type(a) is SomeSubClass
|
||||||
assert type(a) is SomeSubClass
|
|
||||||
|
|
Loading…
Reference in a new issue