Fix buffer protocol inheritance

Fixes #878.
This commit is contained in:
Dean Moldovan
2017-05-28 16:35:02 +02:00
parent 6d2411f1ac
commit 427e4afc69
3 changed files with 28 additions and 2 deletions

View File

@@ -36,6 +36,7 @@ def test_from_python():
@pytest.unsupported_on_pypy
def test_to_python():
m = Matrix(5, 5)
assert memoryview(m).shape == (5, 5)
assert m[2, 3] == 0
m[2, 3] = 4
@@ -63,6 +64,16 @@ def test_to_python():
assert cstats.move_assignments == 0
@pytest.unsupported_on_pypy
def test_inherited_protocol():
"""SquareMatrix is derived from Matrix and inherits the buffer protocol"""
from pybind11_tests import SquareMatrix
matrix = SquareMatrix(5)
assert memoryview(matrix).shape == (5, 5)
assert np.asarray(matrix).shape == (5, 5)
@pytest.unsupported_on_pypy
def test_ptmf():
for cls in [PTMFBuffer, ConstPTMFBuffer, DerivedPTMFBuffer]: