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 4, 2024
1 parent eb409c5 commit ebd7898
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 35 deletions.
6 changes: 4 additions & 2 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,6 +82,8 @@ def test_from_python():
for j in range(m4.cols()):
assert m3[i, j] == m4[i, j]

if env.GRAALPY:
pytest.skip("ConstructorStats is incompatible with GraalPy.")
cstats = ConstructorStats.get(m.Matrix)
assert cstats.alive() == 1
del m3, m4
Expand All @@ -99,7 +100,6 @@ def test_from_python():
@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,6 +120,8 @@ def test_to_python():
mat2[2, 3] = 5
assert mat2[2, 3] == 5

if env.GRAALPY:
pytest.skip("ConstructorStats is incompatible with GraalPy.")
cstats = ConstructorStats.get(m.Matrix)
assert cstats.alive() == 1
del mat
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
9 changes: 6 additions & 3 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,6 +68,9 @@ def test_methods_and_attributes():
instance1.value = 100
assert str(instance1) == "ExampleMandA[value=100]"

if env.GRAALPY:
pytest.skip("ConstructorStats is incompatible with GraalPy.")

cstats = ConstructorStats.get(m.ExampleMandA)
assert cstats.alive() == 2
del instance1, instance2
Expand Down Expand Up @@ -296,7 +298,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 @@ -318,6 +319,8 @@ def test_dynamic_attributes():
instance.__dict__ = []
assert str(excinfo.value) == "__dict__ must be set to a dictionary, not a 'list'"

if env.GRAALPY:
pytest.skip("ConstructorStats is incompatible with GraalPy.")
cstats = ConstructorStats.get(m.DynamicClass)
assert cstats.alive() == 1
del instance
Expand Down
4 changes: 3 additions & 1 deletion 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,6 +39,9 @@ def test_reference_internal():
assert str(b.get_a2()) == "A[43]"
assert str(b.a2) == "A[43]"

if env.GRAALPY:
pytest.skip("ConstructorStats is incompatible with GraalPy.")

astats, bstats = ConstructorStats.get(ms.A), ConstructorStats.get(ms.B)
assert astats.alive() == 2
assert bstats.alive() == 1
Expand Down
26 changes: 15 additions & 11 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,16 @@ def test_mi_unaligned_base():
b2d = m.i801b2_d(d)
assert b2d is d

if env.GRAALPY:
pytest.skip("ConstructorStats is incompatible with 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 +316,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 +329,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
21 changes: 14 additions & 7 deletions tests/test_sequences_and_iterators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from pytest import approx # noqa: PT013

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

Expand Down Expand Up @@ -107,12 +107,12 @@ def test_sliceable():
assert sliceable[50:60:-1] == (50, 60, -1)


@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
def test_sequence():
cstats = ConstructorStats.get(m.Sequence)

s = m.Sequence(5)
assert cstats.values() == ["of size", "5"]
if not env.GRAALPY:
assert cstats.values() == ["of size", "5"]

assert "Sequence" in repr(s)
assert len(s) == 5
Expand All @@ -125,27 +125,34 @@ def test_sequence():
assert s[3] == approx(56.78, rel=1e-05)

rev = reversed(s)
assert cstats.values() == ["of size", "5"]
if not env.GRAALPY:
assert cstats.values() == ["of size", "5"]

rev2 = s[::-1]
assert cstats.values() == ["of size", "5"]
if not env.GRAALPY:
assert cstats.values() == ["of size", "5"]

it = iter(m.Sequence(0))
for _ in range(3): # __next__ must continue to raise StopIteration
with pytest.raises(StopIteration):
next(it)
assert cstats.values() == ["of size", "0"]
if not env.GRAALPY:
assert cstats.values() == ["of size", "0"]

expected = [0, 56.78, 0, 0, 12.34]
assert rev == approx(expected, rel=1e-05)
assert rev2 == approx(expected, rel=1e-05)
assert rev == rev2

rev[0::2] = m.Sequence([2.0, 2.0, 2.0])
assert cstats.values() == ["of size", "3", "from std::vector"]
if not env.GRAALPY:
assert cstats.values() == ["of size", "3", "from std::vector"]

assert rev == approx([2, 56.78, 2, 0, 2], rel=1e-05)

if env.GRAALPY:
pytest.skip("ConstructorStats is incompatible with GraalPy.")

assert cstats.alive() == 4
del it
assert cstats.alive() == 3
Expand Down
18 changes: 10 additions & 8 deletions tests/test_virtual_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,16 @@ def get_string2(self):
"""
)

if not env.GRAALPY:
cstats = ConstructorStats.get(m.ExampleVirt)
assert cstats.alive() == 3
del ex12, ex12p, ex12p2
assert cstats.alive() == 0
assert cstats.values() == ["10", "11", "17"]
assert cstats.copy_constructions == 0
assert cstats.move_constructions >= 0
if env.GRAALPY:
pytest.skip("ConstructorStats is incompatible with GraalPy.")

cstats = ConstructorStats.get(m.ExampleVirt)
assert cstats.alive() == 3
del ex12, ex12p, ex12p2
assert cstats.alive() == 0
assert cstats.values() == ["10", "11", "17"]
assert cstats.copy_constructions == 0
assert cstats.move_constructions >= 0


@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
Expand Down

0 comments on commit ebd7898

Please sign in to comment.