Skip to content

Commit

Permalink
refactor: drop PY3 and failfast
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Aug 14, 2020
1 parent 134f3e7 commit 3f463f1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
10 changes: 1 addition & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,9 @@ def pytest_configure():

# Provide simple `six`-like aliases.
pytest.PY2 = (sys.version_info.major == 2)
pytest.PY3 = (sys.version_info.major == 3)
pytest.CPYTHON = (platform.python_implementation() == "CPython")
pytest.PYPY = (platform.python_implementation() == "PyPy")

if not pytest.PY2 and not pytest.PY3:
print("pybind11 is only supported on Python 2.x or 3.x")
sys.exit(1)
if not pytest.CPYTHON and not pytest.PYPY:
print("pybind11 is only supported for CPython or PyPy")
sys.exit(1)

skipif = pytest.mark.skipif
pytest.suppress = suppress
pytest.requires_numpy = skipif(not np, reason="numpy is not installed")
Expand All @@ -229,7 +221,7 @@ def pytest_configure():
not have_eigen or not scipy, reason="eigen and/or scipy are not installed")
pytest.unsupported_on_pypy = skipif(pytest.PYPY, reason="unsupported on PyPy")
pytest.bug_in_pypy = pytest.mark.xfail(pytest.PYPY, reason="bug in PyPy")
pytest.unsupported_on_pypy3 = skipif(pytest.PYPY and pytest.PY3,
pytest.unsupported_on_pypy3 = skipif(pytest.PYPY and not pytest.PY2,
reason="unsupported on PyPy3")
pytest.unsupported_on_pypy_lt_6 = skipif(pytest.PYPY and sys.pypy_version_info[0] < 6,
reason="unsupported on PyPy<6")
Expand Down
6 changes: 3 additions & 3 deletions tests/test_buffers.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,22 @@ def test_pointer_to_member_fn():
def test_readonly_buffer():
buf = m.BufferReadOnly(0x64)
view = memoryview(buf)
assert view[0] == 0x64 if pytest.PY3 else b'd'
assert view[0] == b'd' if pytest.PY2 else 0x64
assert view.readonly


@pytest.unsupported_on_pypy
def test_selective_readonly_buffer():
buf = m.BufferReadOnlySelect()

memoryview(buf)[0] = 0x64 if pytest.PY3 else b'd'
memoryview(buf)[0] = b'd' if pytest.PY2 else 0x64
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 pytest.PY3 else b'\0'
memoryview(buf)[0] = b'\0' if pytest.PY2 else 0
with pytest.raises(TypeError):
io.BytesIO(b'1').readinto(buf)
4 changes: 2 additions & 2 deletions tests/test_pytypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_bytes(doc):
assert m.bytes_from_str().decode() == "bar"

assert doc(m.bytes_from_str) == "bytes_from_str() -> {}".format(
"bytes" if pytest.PY3 else "str"
"str" if pytest.PY2 else "bytes"
)


Expand Down Expand Up @@ -292,7 +292,7 @@ def test_memoryview(method, args, fmt, expected_view):
view = method(*args)
assert isinstance(view, memoryview)
assert view.format == fmt
if isinstance(expected_view, bytes) or pytest.PY3:
if isinstance(expected_view, bytes) or not pytest.PY2:
view_as_list = list(view)
else:
# Using max to pick non-zero byte (big-endian vs little-endian).
Expand Down
2 changes: 1 addition & 1 deletion tests/test_stl_binders.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_vector_buffer():
assert v[1] == 2
v[2] = 5
mv = memoryview(v) # We expose the buffer interface
if pytest.PY3:
if not pytest.PY2:
assert mv[2] == 5
mv[2] = 6
else:
Expand Down

0 comments on commit 3f463f1

Please sign in to comment.