Changing all but one std::runtime_error to std::invalid_argument, which appears as ValueError in the Python interpreter. Adding test_cannot_disown_use_count_ne_1. (#2883)

This commit is contained in:
Ralf W. Grosse-Kunstleve
2021-03-03 05:08:47 -08:00
committed by GitHub
parent 3a336a2047
commit 6a7e9f42fe
3 changed files with 46 additions and 17 deletions

View File

@@ -85,6 +85,26 @@ def test_pass_unique_ptr_disowns(pass_f, rtrn_f, expected):
)
@pytest.mark.parametrize(
"pass_f, rtrn_f",
[
(m.pass_uqmp, m.rtrn_uqmp),
(m.pass_uqcp, m.rtrn_uqcp),
(m.pass_udmp, m.rtrn_udmp),
(m.pass_udcp, m.rtrn_udcp),
],
)
def test_cannot_disown_use_count_ne_1(pass_f, rtrn_f):
obj = rtrn_f()
stash = m.SharedPtrStash()
stash.Add(obj)
with pytest.raises(ValueError) as exc_info:
pass_f(obj)
assert str(exc_info.value) == (
"Cannot disown use_count != 1 (loaded_as_unique_ptr)."
)
def test_unique_ptr_roundtrip(num_round_trips=1000):
# Multiple roundtrips to stress-test instance registration/deregistration.
recycled = m.atyp("passenger")