mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-20 14:59:27 +00:00
tests: Consolidate version (2 vs. 3) and platform (CPython vs. PyPy) checks (#2376)
Fix logic in test_bytes_to_string Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
This commit is contained in:
@@ -1,15 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
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):
|
||||
@@ -98,7 +95,7 @@ def test_pointer_to_member_fn():
|
||||
def test_readonly_buffer():
|
||||
buf = m.BufferReadOnly(0x64)
|
||||
view = memoryview(buf)
|
||||
assert view[0] == 0x64 if PY3 else b'd'
|
||||
assert view[0] == b'd' if pytest.PY2 else 0x64
|
||||
assert view.readonly
|
||||
|
||||
|
||||
@@ -106,7 +103,7 @@ def test_readonly_buffer():
|
||||
def test_selective_readonly_buffer():
|
||||
buf = m.BufferReadOnlySelect()
|
||||
|
||||
memoryview(buf)[0] = 0x64 if PY3 else b'd'
|
||||
memoryview(buf)[0] = b'd' if pytest.PY2 else 0x64
|
||||
assert buf.value == 0x64
|
||||
|
||||
io.BytesIO(b'A').readinto(buf)
|
||||
@@ -114,6 +111,6 @@ def test_selective_readonly_buffer():
|
||||
|
||||
buf.readonly = True
|
||||
with pytest.raises(TypeError):
|
||||
memoryview(buf)[0] = 0 if PY3 else b'\0'
|
||||
memoryview(buf)[0] = b'\0' if pytest.PY2 else 0
|
||||
with pytest.raises(TypeError):
|
||||
io.BytesIO(b'1').readinto(buf)
|
||||
|
||||
Reference in New Issue
Block a user