MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / test_to_python

Function test_to_python

deps/pybind11-2.13.1/tests/test_buffers.py:101–133  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

99 env.PYPY, reason="PyPy 7.3.7 doesn't clear this anymore", strict=False
100)
101def test_to_python():
102 mat = m.Matrix(5, 4)
103 assert memoryview(mat).shape == (5, 4)
104
105 assert mat[2, 3] == 0
106 mat[2, 3] = 4.0
107 mat[3, 2] = 7.0
108 assert mat[2, 3] == 4
109 assert mat[3, 2] == 7
110 assert struct.unpack_from("f", mat, (3 * 4 + 2) * 4) == (7,)
111 assert struct.unpack_from("f", mat, (2 * 4 + 3) * 4) == (4,)
112
113 mat2 = np.array(mat, copy=False)
114 assert mat2.shape == (5, 4)
115 assert abs(mat2).sum() == 11
116 assert mat2[2, 3] == 4
117 assert mat2[3, 2] == 7
118 mat2[2, 3] = 5
119 assert mat2[2, 3] == 5
120
121 cstats = ConstructorStats.get(m.Matrix)
122 assert cstats.alive() == 1
123 del mat
124 pytest.gc_collect()
125 assert cstats.alive() == 1
126 del mat2 # holds a mat reference
127 pytest.gc_collect()
128 assert cstats.alive() == 0
129 assert cstats.values() == ["5x4 matrix"]
130 assert cstats.copy_constructions == 0
131 # assert cstats.move_constructions >= 0 # Don't invoke any
132 assert cstats.copy_assignments == 0
133 assert cstats.move_assignments == 0
134
135
136def test_inherited_protocol():

Callers

nothing calls this directly

Calls 8

memoryviewClass · 0.85
absFunction · 0.85
MatrixMethod · 0.80
sumMethod · 0.80
aliveMethod · 0.80
arrayMethod · 0.45
getMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected