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

Function test_from_python

tests/test_buffers.py:73–95  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

71
72
73def test_from_python():
74 with pytest.raises(RuntimeError) as excinfo:
75 m.Matrix(np.array([1, 2, 3])) # trying to assign a 1D array
76 assert str(excinfo.value) == "Incompatible buffer format!"
77
78 m3 = np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32)
79 m4 = m.Matrix(m3)
80
81 for i in range(m4.rows()):
82 for j in range(m4.cols()):
83 assert m3[i, j] == m4[i, j]
84
85 if env.GRAALPY:
86 pytest.skip("ConstructorStats is incompatible with GraalPy.")
87 cstats = ConstructorStats.get(m.Matrix)
88 assert cstats.alive() == 1
89 del m3, m4
90 assert cstats.alive() == 0
91 assert cstats.values() == ["2x3 matrix"]
92 assert cstats.copy_constructions == 0
93 # assert cstats.move_constructions >= 0 # Don't invoke any
94 assert cstats.copy_assignments == 0
95 assert cstats.move_assignments == 0
96
97
98# https://foss.heptapod.net/pypy/pypy/-/issues/2444

Callers

nothing calls this directly

Calls 8

rowsMethod · 0.95
colsMethod · 0.95
strClass · 0.85
MatrixMethod · 0.80
arrayMethod · 0.80
aliveMethod · 0.80
valuesMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected