4from pybind11_tests
import copy_move_policies
as m
8 with pytest.raises(RuntimeError)
as excinfo:
9 m.lacking_copy_ctor.get_one()
10 assert "is non-copyable!" in str(excinfo.value)
14 with pytest.raises(RuntimeError)
as excinfo:
15 m.lacking_move_ctor.get_one()
16 assert "is neither movable nor copyable!" in str(excinfo.value)
20 """Cast some values in C++ via custom type casters and count the number of moves/copies."""
22 cstats = m.move_and_copy_cstats()
24 cstats[
"MoveOnlyInt"],
25 cstats[
"MoveOrCopyInt"],
26 cstats[
"CopyOnlyInt"],
32 assert m.move_and_copy_casts(3) == 18
33 assert c_m.copy_assignments + c_m.copy_constructions == 0
34 assert c_m.move_assignments == 2
35 assert c_m.move_constructions >= 2
36 assert c_mc.alive() == 0
37 assert c_mc.copy_assignments + c_mc.copy_constructions == 0
38 assert c_mc.move_assignments == 2
39 assert c_mc.move_constructions >= 2
40 assert c_c.alive() == 0
41 assert c_c.copy_assignments == 2
42 assert c_c.copy_constructions >= 2
43 assert c_m.alive() + c_mc.alive() + c_c.alive() == 0
47 """Call some functions that load arguments via custom type casters and count the number of
50 cstats = m.move_and_copy_cstats()
52 cstats["MoveOnlyInt"],
53 cstats[
"MoveOrCopyInt"],
54 cstats[
"CopyOnlyInt"],
57 assert m.move_only(10) == 10
58 assert m.move_or_copy(11) == 11
59 assert m.copy_only(12) == 12
60 assert m.move_pair((13, 14)) == 27
61 assert m.move_tuple((15, 16, 17)) == 48
62 assert m.copy_tuple((18, 19)) == 37
65 assert m.move_copy_nested((1, ((2, 3, (4,)), 5))) == 15
67 assert c_m.copy_assignments + c_m.copy_constructions == 0
68 assert c_m.move_assignments == 6
69 assert c_m.move_constructions == 9
70 assert c_mc.copy_assignments + c_mc.copy_constructions == 0
71 assert c_mc.move_assignments == 5
72 assert c_mc.move_constructions == 8
73 assert c_c.copy_assignments == 4
74 assert c_c.copy_constructions == 6
75 assert c_m.alive() + c_mc.alive() + c_c.alive() == 0
78@pytest.mark.skipif(not m.has_optional, reason="no <optional>")
80 """Tests move/copy loads of std::optional arguments"""
82 cstats = m.move_and_copy_cstats()
84 cstats[
"MoveOnlyInt"],
85 cstats[
"MoveOrCopyInt"],
86 cstats[
"CopyOnlyInt"],
91 assert m.move_optional(10) == 10
92 assert m.move_or_copy_optional(11) == 11
93 assert m.copy_optional(12) == 12
97 assert m.move_optional_tuple((3, 4, 5)) == 12
99 assert c_m.copy_assignments + c_m.copy_constructions == 0
100 assert c_m.move_assignments == 2
101 assert c_m.move_constructions == 5
102 assert c_mc.copy_assignments + c_mc.copy_constructions == 0
103 assert c_mc.move_assignments == 2
104 assert c_mc.move_constructions == 5
105 assert c_c.copy_assignments == 2
106 assert c_c.copy_constructions == 5
107 assert c_m.alive() + c_mc.alive() + c_c.alive() == 0
111 """An object with a private `operator new` cannot be returned by value"""
113 with pytest.raises(RuntimeError)
as excinfo:
114 m.private_op_new_value()
115 assert "is neither movable nor copyable" in str(excinfo.value)
117 assert m.private_op_new_reference().value == 1
121 """#389: rvp::move should fall-through to copy on non-movable objects"""
123 m1 = m.get_moveissue1(1)
125 m2 = m.get_moveissue2(2)
def test_move_and_copy_loads()
def test_lacking_copy_ctor()
def test_move_and_copy_load_optional()
def test_private_op_new()
def test_lacking_move_ctor()
def test_move_and_copy_casts()