2 from pybind11_tests
import copy_move_policies
as m
6 with pytest.raises(RuntimeError)
as excinfo:
7 m.lacking_copy_ctor.get_one()
8 assert "the object is non-copyable!" in str(excinfo.value)
12 with pytest.raises(RuntimeError)
as excinfo:
13 m.lacking_move_ctor.get_one()
14 assert "the object is neither movable nor copyable!" in str(excinfo.value)
18 """Cast some values in C++ via custom type casters and count the number of moves/copies.""" 20 cstats = m.move_and_copy_cstats()
21 c_m, c_mc, c_c = cstats[
"MoveOnlyInt"], cstats[
"MoveOrCopyInt"], cstats[
"CopyOnlyInt"]
26 assert m.move_and_copy_casts(3) == 18
27 assert c_m.copy_assignments + c_m.copy_constructions == 0
28 assert c_m.move_assignments == 2
29 assert c_m.move_constructions >= 2
30 assert c_mc.alive() == 0
31 assert c_mc.copy_assignments + c_mc.copy_constructions == 0
32 assert c_mc.move_assignments == 2
33 assert c_mc.move_constructions >= 2
34 assert c_c.alive() == 0
35 assert c_c.copy_assignments == 2
36 assert c_c.copy_constructions >= 2
37 assert c_m.alive() + c_mc.alive() + c_c.alive() == 0
41 """Call some functions that load arguments via custom type casters and count the number of 44 cstats = m.move_and_copy_cstats()
45 c_m, c_mc, c_c = cstats[
"MoveOnlyInt"], cstats[
"MoveOrCopyInt"], cstats[
"CopyOnlyInt"]
47 assert m.move_only(10) == 10
48 assert m.move_or_copy(11) == 11
49 assert m.copy_only(12) == 12
50 assert m.move_pair((13, 14)) == 27
51 assert m.move_tuple((15, 16, 17)) == 48
52 assert m.copy_tuple((18, 19)) == 37
55 assert m.move_copy_nested((1, ((2, 3, (4,)), 5))) == 15
57 assert c_m.copy_assignments + c_m.copy_constructions == 0
58 assert c_m.move_assignments == 6
59 assert c_m.move_constructions == 9
60 assert c_mc.copy_assignments + c_mc.copy_constructions == 0
61 assert c_mc.move_assignments == 5
62 assert c_mc.move_constructions == 8
63 assert c_c.copy_assignments == 4
64 assert c_c.copy_constructions == 6
65 assert c_m.alive() + c_mc.alive() + c_c.alive() == 0
68 @pytest.mark.skipif(
not m.has_optional, reason=
'no <optional>')
70 """Tests move/copy loads of std::optional arguments""" 72 cstats = m.move_and_copy_cstats()
73 c_m, c_mc, c_c = cstats[
"MoveOnlyInt"], cstats[
"MoveOrCopyInt"], cstats[
"CopyOnlyInt"]
77 assert m.move_optional(10) == 10
78 assert m.move_or_copy_optional(11) == 11
79 assert m.copy_optional(12) == 12
83 assert m.move_optional_tuple((3, 4, 5)) == 12
85 assert c_m.copy_assignments + c_m.copy_constructions == 0
86 assert c_m.move_assignments == 2
87 assert c_m.move_constructions == 5
88 assert c_mc.copy_assignments + c_mc.copy_constructions == 0
89 assert c_mc.move_assignments == 2
90 assert c_mc.move_constructions == 5
91 assert c_c.copy_assignments == 2
92 assert c_c.copy_constructions == 5
93 assert c_m.alive() + c_mc.alive() + c_c.alive() == 0
97 """An object with a private `operator new` cannot be returned by value""" 99 with pytest.raises(RuntimeError)
as excinfo:
100 m.private_op_new_value()
101 assert "the object is neither movable nor copyable" in str(excinfo.value)
103 assert m.private_op_new_reference().value == 1
107 """#389: rvp::move should fall-through to copy on non-movable objects""" 109 m2 = m.get_moveissue2(2)
111 m1 = m.get_moveissue1(1)
def test_lacking_move_ctor()
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()