MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_cpp_casting

Function test_cpp_casting

tests/test_eigen_matrix.py:120–140  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

118
119
120def test_cpp_casting():
121 assert m.cpp_copy(m.fixed_r()) == 22.0
122 assert m.cpp_copy(m.fixed_c()) == 22.0
123 z = np.array([[5.0, 6], [7, 8]])
124 assert m.cpp_copy(z) == 7.0
125 assert m.cpp_copy(m.get_cm_ref()) == 21.0
126 assert m.cpp_copy(m.get_rm_ref()) == 21.0
127 assert m.cpp_ref_c(m.get_cm_ref()) == 21.0
128 assert m.cpp_ref_r(m.get_rm_ref()) == 21.0
129 with pytest.raises(RuntimeError) as excinfo:
130 # Can't reference m.fixed_c: it contains floats, m.cpp_ref_any wants doubles
131 m.cpp_ref_any(m.fixed_c())
132 assert "Unable to cast Python instance" in str(excinfo.value)
133 with pytest.raises(RuntimeError) as excinfo:
134 # Can't reference m.fixed_r: it contains floats, m.cpp_ref_any wants doubles
135 m.cpp_ref_any(m.fixed_r())
136 assert "Unable to cast Python instance" in str(excinfo.value)
137 assert m.cpp_ref_any(m.ReturnTester.create()) == 1.0
138
139 assert m.cpp_ref_any(m.get_cm_ref()) == 21.0
140 assert m.cpp_ref_any(m.get_cm_ref()) == 21.0
141
142
143def test_pass_readonly_array():

Callers

nothing calls this directly

Calls 3

strClass · 0.85
arrayMethod · 0.80
createMethod · 0.45

Tested by

no test coverage detected