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

Function test_numpy_view

tests/test_numpy_array.py:285–315  ·  view source on GitHub ↗
(capture)

Source from the content-addressed store, hash-verified

283
284@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
285def test_numpy_view(capture):
286 with capture:
287 ac = m.ArrayClass()
288 ac_view_1 = ac.numpy_view()
289 ac_view_2 = ac.numpy_view()
290 assert np.all(ac_view_1 == np.array([1, 2], dtype=np.int32))
291 del ac
292 pytest.gc_collect()
293 assert (
294 capture
295 == """
296 ArrayClass()
297 ArrayClass::numpy_view()
298 ArrayClass::numpy_view()
299 """
300 )
301 ac_view_1[0] = 4
302 ac_view_1[1] = 3
303 assert ac_view_2[0] == 4
304 assert ac_view_2[1] == 3
305 with capture:
306 del ac_view_1
307 del ac_view_2
308 pytest.gc_collect()
309 pytest.gc_collect()
310 assert (
311 capture
312 == """
313 ~ArrayClass()
314 """
315 )
316
317
318def test_cast_numpy_int64_to_uint64():

Callers

nothing calls this directly

Calls 2

ArrayClassMethod · 0.80
arrayMethod · 0.80

Tested by

no test coverage detected