Skip to content

Commit

Permalink
PyPy >=3.9 doesn't like __doc__ properties; skip these tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eriknw committed Jan 23, 2024
1 parent 6eed9f1 commit 4e2736f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 12 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ jobs:
steps:
- name: Setup QEMU
if: ${{ matrix.os == 'ubuntu' }}
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Checkout
Expand All @@ -182,7 +182,7 @@ jobs:
with:
python-version: "3.x"
- name: Build wheels
uses: pypa/cibuildwheel@v2.14.1
uses: pypa/cibuildwheel@v2.16.2
env:
CIBW_BUILD: ${{ matrix.build }}
CIBW_ARCHS: ${{ matrix.arch }}
Expand Down Expand Up @@ -237,7 +237,7 @@ jobs:
run: |
ls -al dist/
- name: Publish to PyPI
uses: pypa/[email protected].8
uses: pypa/[email protected].11
if: startsWith(github.ref, 'refs/tags/')
with:
user: __token__
Expand Down
30 changes: 21 additions & 9 deletions cytoolz/tests/test_functoolz.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import inspect
import sys
import cytoolz
from cytoolz.functoolz import (thread_first, thread_last, memoize, curry,
compose, compose_left, pipe, complement, do, juxt,
Expand All @@ -7,6 +8,12 @@
from cytoolz.utils import raises
from functools import partial

IS_PYPY_GE_39 = (
sys.implementation.name == "pypy"
and sys.version_info.major == 3
and sys.version_info.minor >= 9
)


def iseven(x):
return x % 2 == 0
Expand Down Expand Up @@ -253,7 +260,8 @@ def f(x, y):
return x

g = curry(f)
assert g.__doc__ == f.__doc__
if not IS_PYPY_GE_39: # pypy >=3.9 doesn't like __doc__ property
assert g.__doc__ == f.__doc__
assert str(g) == str(f)
assert f(1, 2) == g(1, 2)

Expand Down Expand Up @@ -582,14 +590,16 @@ def g(a):

composed = compose(f, g)
assert composed.__name__ == 'f_of_g'
assert composed.__doc__ == 'lambda *args, **kwargs: f(g(*args, **kwargs))'
if not IS_PYPY_GE_39: # pypy >=3.9 doesn't like __doc__ property
assert composed.__doc__ == 'lambda *args, **kwargs: f(g(*args, **kwargs))'

# Create an object with no __name__.
h = object()

composed = compose(f, h)
assert composed.__name__ == 'Compose'
assert composed.__doc__ == 'A composition of functions'
if not IS_PYPY_GE_39: # pypy >=3.9 doesn't like __doc__ property
assert composed.__doc__ == 'A composition of functions'

assert repr(composed) == 'Compose({!r}, {!r})'.format(f, h)

Expand Down Expand Up @@ -760,9 +770,10 @@ def handler(e):
assert excepting(3) == -1

assert excepting.__name__ == 'idx_excepting_ValueError'
assert 'idx docstring' in excepting.__doc__
assert 'ValueError' in excepting.__doc__
assert 'handler docstring' in excepting.__doc__
if not IS_PYPY_GE_39: # pypy >=3.9 doesn't like __doc__ property
assert 'idx docstring' in excepting.__doc__
assert 'ValueError' in excepting.__doc__
assert 'handler docstring' in excepting.__doc__

def getzero(a):
"""getzero docstring
Expand All @@ -776,9 +787,10 @@ def getzero(a):
assert excepting({0: 1}) == 1

assert excepting.__name__ == 'getzero_excepting_IndexError_or_KeyError'
assert 'getzero docstring' in excepting.__doc__
assert 'return_none' in excepting.__doc__
assert 'Returns None' in excepting.__doc__
if not IS_PYPY_GE_39: # pypy >=3.9 doesn't like __doc__ property
assert 'getzero docstring' in excepting.__doc__
assert 'return_none' in excepting.__doc__
assert 'Returns None' in excepting.__doc__

def raise_(a):
"""A function that raises an instance of the exception type given.
Expand Down
25 changes: 25 additions & 0 deletions cytoolz/tests/test_itertoolz.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,34 @@ def test_unique():


def test_isiterable():
# objects that have a __iter__() or __getitem__() method are iterable
# https://docs.python.org/3/library/functions.html#iter
class IterIterable:
def __iter__(self):
return iter(["a", "b", "c"])

class GetItemIterable:
def __getitem__(self, item):
return ["a", "b", "c"][item]

# "if a class sets __iter__() to None, the class is not iterable"
# https://docs.python.org/3/reference/datamodel.html#special-method-names
class NotIterable:
__iter__ = None

class NotIterableEvenWithGetItem:
__iter__ = None

def __getitem__(self, item):
return ["a", "b", "c"][item]

assert isiterable([1, 2, 3]) is True
assert isiterable('abc') is True
assert isiterable(IterIterable()) is True
assert isiterable(GetItemIterable()) is True
assert isiterable(5) is False
assert isiterable(NotIterable()) is False
assert isiterable(NotIterableEvenWithGetItem()) is False


def test_isdistinct():
Expand Down

0 comments on commit 4e2736f

Please sign in to comment.