Skip to content

Commit

Permalink
Also check PyBUF_FORMAT results
Browse files Browse the repository at this point in the history
  • Loading branch information
QuLogic committed Nov 5, 2024
1 parent 83f6ec5 commit 63d6fd2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/test_buffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ TEST_SUBMODULE(buffers, m) {
m.def("get_buffer_info", [](const py::buffer &buffer) { return buffer.request(); });

// Expose Py_buffer for testing.
m.attr("PyBUF_FORMAT") = PyBUF_FORMAT;
m.attr("PyBUF_SIMPLE") = PyBUF_SIMPLE;
m.attr("PyBUF_ND") = PyBUF_ND;
m.attr("PyBUF_STRIDES") = PyBUF_STRIDES;
Expand Down
10 changes: 10 additions & 0 deletions tests/test_buffers.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,16 @@ def test_c_contiguous_to_pybuffer(type):
raise ValueError(f"Unknown parametrization {type}")

info = m.get_py_buffer(mat, m.PyBUF_SIMPLE)
assert info.format is None
assert info.itemsize == ctypes.sizeof(ctypes.c_float)
assert info.len == 5 * 4 * info.itemsize
assert info.ndim == 0 # See discussion on PR #5407.
assert info.shape is None
assert info.strides is None
assert info.suboffsets is None
assert not info.readonly
info = m.get_py_buffer(mat, m.PyBUF_SIMPLE | m.PyBUF_FORMAT)
assert info.format == "f"
assert info.itemsize == ctypes.sizeof(ctypes.c_float)
assert info.len == 5 * 4 * info.itemsize
assert info.ndim == 0 # See discussion on PR #5407.
Expand Down

0 comments on commit 63d6fd2

Please sign in to comment.