3 from pybind11_tests
import copy_move_policies
as m
7 with pytest.raises(RuntimeError)
as excinfo:
8 m.lacking_copy_ctor.get_one()
9 assert "is non-copyable!" in str(excinfo.value)
13 with pytest.raises(RuntimeError)
as excinfo:
14 m.lacking_move_ctor.get_one()
15 assert "is neither movable nor copyable!" in str(excinfo.value)
19 """Cast some values in C++ via custom type casters and count the number of moves/copies.""" 21 cstats = m.move_and_copy_cstats()
23 cstats[
"MoveOnlyInt"],
24 cstats[
"MoveOrCopyInt"],
25 cstats[
"CopyOnlyInt"],
31 assert m.move_and_copy_casts(3) == 18
32 assert c_m.copy_assignments + c_m.copy_constructions == 0
33 assert c_m.move_assignments == 2
34 assert c_m.move_constructions >= 2
35 assert c_mc.alive() == 0
36 assert c_mc.copy_assignments + c_mc.copy_constructions == 0
37 assert c_mc.move_assignments == 2
38 assert c_mc.move_constructions >= 2
39 assert c_c.alive() == 0
40 assert c_c.copy_assignments == 2
41 assert c_c.copy_constructions >= 2
42 assert c_m.alive() + c_mc.alive() + c_c.alive() == 0
46 """Call some functions that load arguments via custom type casters and count the number of 49 cstats = m.move_and_copy_cstats()
51 cstats[
"MoveOnlyInt"],
52 cstats[
"MoveOrCopyInt"],
53 cstats[
"CopyOnlyInt"],
56 assert m.move_only(10) == 10
57 assert m.move_or_copy(11) == 11
58 assert m.copy_only(12) == 12
59 assert m.move_pair((13, 14)) == 27
60 assert m.move_tuple((15, 16, 17)) == 48
61 assert m.copy_tuple((18, 19)) == 37
64 assert m.move_copy_nested((1, ((2, 3, (4,)), 5))) == 15
66 assert c_m.copy_assignments + c_m.copy_constructions == 0
67 assert c_m.move_assignments == 6
68 assert c_m.move_constructions == 9
69 assert c_mc.copy_assignments + c_mc.copy_constructions == 0
70 assert c_mc.move_assignments == 5
71 assert c_mc.move_constructions == 8
72 assert c_c.copy_assignments == 4
73 assert c_c.copy_constructions == 6
74 assert c_m.alive() + c_mc.alive() + c_c.alive() == 0
77 @pytest.mark.skipif(
not m.has_optional, reason=
"no <optional>")
79 """Tests move/copy loads of std::optional arguments""" 81 cstats = m.move_and_copy_cstats()
83 cstats[
"MoveOnlyInt"],
84 cstats[
"MoveOrCopyInt"],
85 cstats[
"CopyOnlyInt"],
90 assert m.move_optional(10) == 10
91 assert m.move_or_copy_optional(11) == 11
92 assert m.copy_optional(12) == 12
96 assert m.move_optional_tuple((3, 4, 5)) == 12
98 assert c_m.copy_assignments + c_m.copy_constructions == 0
99 assert c_m.move_assignments == 2
100 assert c_m.move_constructions == 5
101 assert c_mc.copy_assignments + c_mc.copy_constructions == 0
102 assert c_mc.move_assignments == 2
103 assert c_mc.move_constructions == 5
104 assert c_c.copy_assignments == 2
105 assert c_c.copy_constructions == 5
106 assert c_m.alive() + c_mc.alive() + c_c.alive() == 0
110 """An object with a private `operator new` cannot be returned by value""" 112 with pytest.raises(RuntimeError)
as excinfo:
113 m.private_op_new_value()
114 assert "is neither movable nor copyable" in str(excinfo.value)
116 assert m.private_op_new_reference().value == 1
120 """#389: rvp::move should fall-through to copy on non-movable objects""" 122 m1 = m.get_moveissue1(1)
124 m2 = m.get_moveissue2(2)
129 """Make sure that cast from pytype rvalue to other pytype works""" 131 value = m.get_pytype_rvalue_castissue(1.0)
def test_lacking_move_ctor()
def test_pytype_rvalue_cast()
def test_private_op_new()
def test_lacking_copy_ctor()
def test_move_and_copy_casts()
def test_move_and_copy_loads()
def test_move_and_copy_load_optional()