Skip to content

Commit 946c198

Browse files
authored
Test fixes for Python 3.13 (#206)
1 parent 85b03a5 commit 946c198

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

Diff for: cytoolz/functoolz.pyx

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ __all__ = ['identity', 'thread_first', 'thread_last', 'memoize', 'compose', 'com
2727

2828

2929
cpdef object identity(object x):
30+
""" Identity function. Return x
31+
32+
>>> identity(3)
33+
3
34+
"""
3035
return x
3136

3237

Diff for: cytoolz/tests/test_docstrings.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ def test_docstrings_uptodate():
4949
d = merge_with(identity, toolz_dict, cytoolz_dict)
5050
for key, (toolz_func, cytoolz_func) in d.items():
5151
# only check if the new doctstring *contains* the expected docstring
52-
toolz_doc = convertdoc(toolz_func)
53-
cytoolz_doc = cytoolz_func.__doc__
52+
# in Python < 3.13 the second line is indented, in 3.13+
53+
# it is not, strip all lines to fudge it
54+
toolz_doc = "\n".join((line.strip() for line in convertdoc(toolz_func).splitlines()))
55+
cytoolz_doc = "\n".join((line.strip() for line in cytoolz_func.__doc__.splitlines()))
5456
if toolz_doc not in cytoolz_doc:
5557
diff = list(differ.compare(toolz_doc.splitlines(),
5658
cytoolz_doc.splitlines()))

Diff for: cytoolz/tests/test_functoolz.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -748,10 +748,13 @@ def f(a, b):
748748
def test_excepts():
749749
# These are descriptors, make sure this works correctly.
750750
assert excepts.__name__ == 'excepts'
751+
# in Python < 3.13 the second line is indented, in 3.13+
752+
# it is not, strip all lines to fudge it
753+
testlines = "\n".join((line.strip() for line in excepts.__doc__.splitlines()))
751754
assert (
752755
'A wrapper around a function to catch exceptions and\n'
753-
' dispatch to a handler.\n'
754-
) in excepts.__doc__
756+
'dispatch to a handler.\n'
757+
) in testlines
755758

756759
def idx(a):
757760
"""idx docstring

Diff for: cytoolz/tests/test_inspect_args.py

+21-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import inspect
33
import itertools
44
import operator
5+
import sys
56
import cytoolz
67
from cytoolz.functoolz import (curry, is_valid_args, is_partial_args, is_arity,
78
num_required_args, has_varargs, has_keywords)
@@ -482,6 +483,23 @@ def __wrapped__(self):
482483
wrapped = Wrapped(func)
483484
assert inspect.signature(func) == inspect.signature(wrapped)
484485

485-
assert num_required_args(Wrapped) is None
486-
_sigs.signatures[Wrapped] = (_sigs.expand_sig((0, lambda func: None)),)
487-
assert num_required_args(Wrapped) == 1
486+
# inspect.signature did not used to work properly on wrappers,
487+
# but it was fixed in Python 3.11.9, Python 3.12.3 and Python
488+
# 3.13+
489+
inspectbroken = True
490+
if sys.version_info.major > 3:
491+
inspectbroken = False
492+
if sys.version_info.major == 3:
493+
if sys.version_info.minor == 11 and sys.version_info.micro > 8:
494+
inspectbroken = False
495+
if sys.version_info.minor == 12 and sys.version_info.micro > 2:
496+
inspectbroken = False
497+
if sys.version_info.minor > 12:
498+
inspectbroken = False
499+
500+
if inspectbroken:
501+
assert num_required_args(Wrapped) is None
502+
_sigs.signatures[Wrapped] = (_sigs.expand_sig((0, lambda func: None)),)
503+
assert num_required_args(Wrapped) == 1
504+
else:
505+
assert num_required_args(Wrapped) is 1

0 commit comments

Comments
 (0)