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

Function test_vector_buffer

tests/test_stl_binders.py:71–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

69
70# Older PyPy's failed here, related to the PyPy's buffer protocol.
71def test_vector_buffer():
72 b = bytearray([1, 2, 3, 4])
73 v = m.VectorUChar(b)
74 assert v[1] == 2
75 v[2] = 5
76 mv = memoryview(v) # We expose the buffer interface
77 assert mv[2] == 5
78 mv[2] = 6
79 assert v[2] == 6
80
81 mv = memoryview(b)
82 v = m.VectorUChar(mv[::2])
83 assert v[1] == 3
84
85 with pytest.raises(RuntimeError) as excinfo:
86 m.create_undeclstruct() # Undeclared struct contents, no buffer interface
87 assert "NumPy type info missing for " in str(excinfo.value)
88
89
90def test_vector_buffer_numpy():

Callers

nothing calls this directly

Calls 3

bytearrayClass · 0.85
memoryviewClass · 0.85
strClass · 0.85

Tested by

no test coverage detected