forked from google/pybind11clif
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust to behavior change due to pybind/pybind11#4586 (smart_holder b…
…ranch). The behavior change made it possible to exercise the `reference_internal` vs `copy` behavior more thoroughly, which then led to a surprise discovery. See SURPRISE comment in tests/test_class_sh_property_stl.py
- Loading branch information
Ralf W. Grosse-Kunstleve
committed
Mar 24, 2023
1 parent
f80b55b
commit 1bcd8e8
Showing
2 changed files
with
33 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,31 @@ | ||
import pytest | ||
|
||
from pybind11_tests import class_sh_property_stl as m | ||
|
||
|
||
def test_vec_fld_hld_ref(): | ||
vfh = m.VectorFieldHolder() | ||
vfh0 = vfh.vec_fld_hld_ref[0] | ||
with pytest.raises(RuntimeError) as exc_info: | ||
vfh0.fld | ||
assert str(exc_info.value) == "Non-owning holder (loaded_as_shared_ptr)." | ||
def test_cpy_after_ref(): | ||
h = m.VectorFieldHolder() | ||
c1 = h.vec_fld_hld_cpy | ||
c2 = h.vec_fld_hld_cpy | ||
assert repr(c2) != repr(c1) | ||
r1 = h.vec_fld_hld_ref | ||
assert repr(r1) != repr(c2) | ||
assert repr(r1) != repr(c1) | ||
r2 = h.vec_fld_hld_ref | ||
assert repr(r2) == repr(r1) | ||
c3 = h.vec_fld_hld_cpy | ||
assert repr(c3) == repr(r1) # SURPRISE! | ||
|
||
|
||
def test_persistent_holder(): | ||
h = m.VectorFieldHolder() | ||
c0 = h.vec_fld_hld_cpy[0] # Must be first. See test_cpy_after_ref(). | ||
r0 = h.vec_fld_hld_ref[0] # Must be second. | ||
assert c0.fld.wrapped_int == 300 | ||
assert r0.fld.wrapped_int == 300 | ||
h.reset_at(0, 400) | ||
assert c0.fld.wrapped_int == 300 | ||
assert r0.fld.wrapped_int == 400 | ||
|
||
|
||
def test_vec_fld_hld_cpy(): | ||
vfh = m.VectorFieldHolder() | ||
vfh0 = vfh.vec_fld_hld_cpy[0] | ||
assert vfh0.fld.wrapped_int == 300 | ||
def test_temporary_holder_keep_alive(): | ||
r0 = m.VectorFieldHolder().vec_fld_hld_ref[0] | ||
assert r0.fld.wrapped_int == 300 |