mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-20 14:59:27 +00:00
committed by
Wenzel Jakob
parent
bd24155b8b
commit
dc65d66171
@@ -1,8 +1,14 @@
|
||||
import io
|
||||
import struct
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from pybind11_tests import buffers as m
|
||||
from pybind11_tests import ConstructorStats
|
||||
|
||||
PY3 = sys.version_info[0] >= 3
|
||||
|
||||
pytestmark = pytest.requires_numpy
|
||||
|
||||
with pytest.suppress(ImportError):
|
||||
@@ -85,3 +91,28 @@ def test_pointer_to_member_fn():
|
||||
buf.value = 0x12345678
|
||||
value = struct.unpack('i', bytearray(buf))[0]
|
||||
assert value == 0x12345678
|
||||
|
||||
|
||||
@pytest.unsupported_on_pypy
|
||||
def test_readonly_buffer():
|
||||
buf = m.BufferReadOnly(0x64)
|
||||
view = memoryview(buf)
|
||||
assert view[0] == 0x64 if PY3 else b'd'
|
||||
assert view.readonly
|
||||
|
||||
|
||||
@pytest.unsupported_on_pypy
|
||||
def test_selective_readonly_buffer():
|
||||
buf = m.BufferReadOnlySelect()
|
||||
|
||||
memoryview(buf)[0] = 0x64 if PY3 else b'd'
|
||||
assert buf.value == 0x64
|
||||
|
||||
io.BytesIO(b'A').readinto(buf)
|
||||
assert buf.value == ord(b'A')
|
||||
|
||||
buf.readonly = True
|
||||
with pytest.raises(TypeError):
|
||||
memoryview(buf)[0] = 0 if PY3 else b'\0'
|
||||
with pytest.raises(TypeError):
|
||||
io.BytesIO(b'1').readinto(buf)
|
||||
|
||||
Reference in New Issue
Block a user