Skip to content

Commit

Permalink
Try to narrow down skipped tests
Browse files Browse the repository at this point in the history
  • Loading branch information
msimacek committed Oct 3, 2024
1 parent eb409c5 commit 4f1fdfe
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 108 deletions.
48 changes: 24 additions & 24 deletions tests/test_buffers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def test_format_descriptor_format_buffer_info_equiv(cpp_name, np_dtype):
assert not np_array_is_matching


@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
def test_from_python():
with pytest.raises(RuntimeError) as excinfo:
m.Matrix(np.array([1, 2, 3])) # trying to assign a 1D array
Expand All @@ -83,23 +82,23 @@ def test_from_python():
for j in range(m4.cols()):
assert m3[i, j] == m4[i, j]

cstats = ConstructorStats.get(m.Matrix)
assert cstats.alive() == 1
del m3, m4
assert cstats.alive() == 0
assert cstats.values() == ["2x3 matrix"]
assert cstats.copy_constructions == 0
# assert cstats.move_constructions >= 0 # Don't invoke any
assert cstats.copy_assignments == 0
assert cstats.move_assignments == 0
if not env.GRAALPY:
cstats = ConstructorStats.get(m.Matrix)
assert cstats.alive() == 1
del m3, m4
assert cstats.alive() == 0
assert cstats.values() == ["2x3 matrix"]
assert cstats.copy_constructions == 0
# assert cstats.move_constructions >= 0 # Don't invoke any
assert cstats.copy_assignments == 0
assert cstats.move_assignments == 0


# https://foss.heptapod.net/pypy/pypy/-/issues/2444
# TODO: fix on recent PyPy
@pytest.mark.xfail(
env.PYPY, reason="PyPy 7.3.7 doesn't clear this anymore", strict=False
)
@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
def test_to_python():
mat = m.Matrix(5, 4)
assert memoryview(mat).shape == (5, 4)
Expand All @@ -120,19 +119,20 @@ def test_to_python():
mat2[2, 3] = 5
assert mat2[2, 3] == 5

cstats = ConstructorStats.get(m.Matrix)
assert cstats.alive() == 1
del mat
pytest.gc_collect()
assert cstats.alive() == 1
del mat2 # holds a mat reference
pytest.gc_collect()
assert cstats.alive() == 0
assert cstats.values() == ["5x4 matrix"]
assert cstats.copy_constructions == 0
# assert cstats.move_constructions >= 0 # Don't invoke any
assert cstats.copy_assignments == 0
assert cstats.move_assignments == 0
if not env.GRAALPY:
cstats = ConstructorStats.get(m.Matrix)
assert cstats.alive() == 1
del mat
pytest.gc_collect()
assert cstats.alive() == 1
del mat2 # holds a mat reference
pytest.gc_collect()
assert cstats.alive() == 0
assert cstats.values() == ["5x4 matrix"]
assert cstats.copy_constructions == 0
# assert cstats.move_constructions >= 0 # Don't invoke any
assert cstats.copy_assignments == 0
assert cstats.move_assignments == 0


def test_inherited_protocol():
Expand Down
8 changes: 5 additions & 3 deletions tests/test_cpp_conduit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import home_planet_very_lonely_traveler
import pytest

import env # noqa: F401
import env
from pybind11_tests import cpp_conduit as home_planet


Expand All @@ -21,15 +21,17 @@ def test_premium_traveler_getattr_actually_exists():
assert t_h.secret_name == "PremiumTraveler GetAttr: secret_name points: 7"


@pytest.mark.xfail("env.GRAALPY", reason="TODO should get fixed on GraalPy side")
def test_call_cpp_conduit_success():
t_h = home_planet.Traveler("home")
cap = t_h._pybind11_conduit_v1_(
home_planet.PYBIND11_PLATFORM_ABI_ID,
home_planet.cpp_type_info_capsule_Traveler,
b"raw_pointer_ephemeral",
)
assert cap.__class__.__name__ == "PyCapsule"
assert cap.__class__.__name__ == "PyCapsule" or (
# Note: this will become unnecessary in the next GraalPy release
env.GRAALPY and cap.__class__.__name__ == "capsule"
)


def test_call_cpp_conduit_platform_abi_id_mismatch():
Expand Down
49 changes: 26 additions & 23 deletions tests/test_methods_and_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

import env # noqa: F401
import env
from pybind11_tests import ConstructorStats
from pybind11_tests import methods_and_attributes as m

Expand All @@ -19,7 +19,6 @@
)


@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
def test_methods_and_attributes():
instance1 = m.ExampleMandA()
instance2 = m.ExampleMandA(32)
Expand Down Expand Up @@ -69,16 +68,17 @@ def test_methods_and_attributes():
instance1.value = 100
assert str(instance1) == "ExampleMandA[value=100]"

cstats = ConstructorStats.get(m.ExampleMandA)
assert cstats.alive() == 2
del instance1, instance2
assert cstats.alive() == 0
assert cstats.values() == ["32"]
assert cstats.default_constructions == 1
assert cstats.copy_constructions == 2
assert cstats.move_constructions >= 2
assert cstats.copy_assignments == 0
assert cstats.move_assignments == 0
if not env.GRAALPY:
cstats = ConstructorStats.get(m.ExampleMandA)
assert cstats.alive() == 2
del instance1, instance2
assert cstats.alive() == 0
assert cstats.values() == ["32"]
assert cstats.default_constructions == 1
assert cstats.copy_constructions == 2
assert cstats.move_constructions >= 2
assert cstats.copy_assignments == 0
assert cstats.move_assignments == 0


def test_copy_method():
Expand Down Expand Up @@ -296,7 +296,6 @@ def test_property_rvalue_policy():

# https://foss.heptapod.net/pypy/pypy/-/issues/2447
@pytest.mark.xfail("env.PYPY")
@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
def test_dynamic_attributes():
instance = m.DynamicClass()
assert not hasattr(instance, "foo")
Expand All @@ -314,14 +313,17 @@ def test_dynamic_attributes():
assert not hasattr(instance, "foo")
assert hasattr(instance, "bar")

with pytest.raises(TypeError) as excinfo:
instance.__dict__ = []
assert str(excinfo.value) == "__dict__ must be set to a dictionary, not a 'list'"
if not env.GRAALPY:
with pytest.raises(TypeError) as excinfo:
instance.__dict__ = []
assert (
str(excinfo.value) == "__dict__ must be set to a dictionary, not a 'list'"
)

cstats = ConstructorStats.get(m.DynamicClass)
assert cstats.alive() == 1
del instance
assert cstats.alive() == 0
cstats = ConstructorStats.get(m.DynamicClass)
assert cstats.alive() == 1
del instance
assert cstats.alive() == 0

# Derived classes should work as well
class PythonDerivedDynamicClass(m.DynamicClass):
Expand All @@ -332,9 +334,10 @@ class PythonDerivedDynamicClass(m.DynamicClass):
derived.foobar = 100
assert derived.foobar == 100

assert cstats.alive() == 1
del derived
assert cstats.alive() == 0
if not env.GRAALPY:
assert cstats.alive() == 1
del derived
assert cstats.alive() == 0


# https://foss.heptapod.net/pypy/pypy/-/issues/2447
Expand Down
38 changes: 19 additions & 19 deletions tests/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def test_nested_modules():
assert ms.submodule_func() == "submodule_func()"


@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
def test_reference_internal():
b = ms.B()
assert str(b.get_a1()) == "A[1]"
Expand All @@ -40,24 +39,25 @@ def test_reference_internal():
assert str(b.get_a2()) == "A[43]"
assert str(b.a2) == "A[43]"

astats, bstats = ConstructorStats.get(ms.A), ConstructorStats.get(ms.B)
assert astats.alive() == 2
assert bstats.alive() == 1
del b
assert astats.alive() == 0
assert bstats.alive() == 0
assert astats.values() == ["1", "2", "42", "43"]
assert bstats.values() == []
assert astats.default_constructions == 0
assert bstats.default_constructions == 1
assert astats.copy_constructions == 0
assert bstats.copy_constructions == 0
# assert astats.move_constructions >= 0 # Don't invoke any
# assert bstats.move_constructions >= 0 # Don't invoke any
assert astats.copy_assignments == 2
assert bstats.copy_assignments == 0
assert astats.move_assignments == 0
assert bstats.move_assignments == 0
if not env.GRAALPY:
astats, bstats = ConstructorStats.get(ms.A), ConstructorStats.get(ms.B)
assert astats.alive() == 2
assert bstats.alive() == 1
del b
assert astats.alive() == 0
assert bstats.alive() == 0
assert astats.values() == ["1", "2", "42", "43"]
assert bstats.values() == []
assert astats.default_constructions == 0
assert bstats.default_constructions == 1
assert astats.copy_constructions == 0
assert bstats.copy_constructions == 0
# assert astats.move_constructions >= 0 # Don't invoke any
# assert bstats.move_constructions >= 0 # Don't invoke any
assert astats.copy_assignments == 2
assert bstats.copy_assignments == 0
assert astats.move_assignments == 0
assert bstats.move_assignments == 0


def test_importing():
Expand Down
34 changes: 18 additions & 16 deletions tests/test_multiple_inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

import env # noqa: F401
import env
from pybind11_tests import ConstructorStats
from pybind11_tests import multiple_inheritance as m

Expand Down Expand Up @@ -272,16 +272,16 @@ def test_mi_dynamic_attributes():
assert d.dynamic == 1


@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
def test_mi_unaligned_base():
"""Returning an offset (non-first MI) base class pointer should recognize the instance"""

n_inst = ConstructorStats.detail_reg_inst()

c = m.I801C()
d = m.I801D()
# + 4 below because we have the two instances, and each instance has offset base I801B2
assert ConstructorStats.detail_reg_inst() == n_inst + 4
if not env.GRAALPY:
# + 4 below because we have the two instances, and each instance has offset base I801B2
assert ConstructorStats.detail_reg_inst() == n_inst + 4
b1c = m.i801b1_c(c)
assert b1c is c
b2c = m.i801b2_c(c)
Expand All @@ -291,14 +291,14 @@ def test_mi_unaligned_base():
b2d = m.i801b2_d(d)
assert b2d is d

assert ConstructorStats.detail_reg_inst() == n_inst + 4 # no extra instances
del c, b1c, b2c
assert ConstructorStats.detail_reg_inst() == n_inst + 2
del d, b1d, b2d
assert ConstructorStats.detail_reg_inst() == n_inst
if not env.GRAALPY:
assert ConstructorStats.detail_reg_inst() == n_inst + 4 # no extra instances
del c, b1c, b2c
assert ConstructorStats.detail_reg_inst() == n_inst + 2
del d, b1d, b2d
assert ConstructorStats.detail_reg_inst() == n_inst


@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
def test_mi_base_return():
"""Tests returning an offset (non-first MI) base class pointer to a derived instance"""

Expand All @@ -314,7 +314,8 @@ def test_mi_base_return():
assert d1.a == 1
assert d1.b == 2

assert ConstructorStats.detail_reg_inst() == n_inst + 4
if not env.GRAALPY:
assert ConstructorStats.detail_reg_inst() == n_inst + 4

c2 = m.i801c_b2()
assert type(c2) is m.I801C
Expand All @@ -326,12 +327,13 @@ def test_mi_base_return():
assert d2.a == 1
assert d2.b == 2

assert ConstructorStats.detail_reg_inst() == n_inst + 8
if not env.GRAALPY:
assert ConstructorStats.detail_reg_inst() == n_inst + 8

del c2
assert ConstructorStats.detail_reg_inst() == n_inst + 6
del c1, d1, d2
assert ConstructorStats.detail_reg_inst() == n_inst
del c2
assert ConstructorStats.detail_reg_inst() == n_inst + 6
del c1, d1, d2
assert ConstructorStats.detail_reg_inst() == n_inst

# Returning an unregistered derived type with a registered base; we won't
# pick up the derived type, obviously, but should still work (as an object
Expand Down
Loading

0 comments on commit 4f1fdfe

Please sign in to comment.