Skip to content

Commit 0c2b43a

Browse files
authored
Test fixes for changes in recent upstream Python (#582)
1 parent 7a0382e commit 0c2b43a

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

toolz/tests/test_functoolz.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -738,10 +738,13 @@ def f(a, b):
738738
def test_excepts():
739739
# These are descriptors, make sure this works correctly.
740740
assert excepts.__name__ == 'excepts'
741+
# in Python < 3.13 the second line is indented, in 3.13+
742+
# it is not, strip all lines to fudge it
743+
testlines = "\n".join((line.strip() for line in excepts.__doc__.splitlines()))
741744
assert (
742745
'A wrapper around a function to catch exceptions and\n'
743-
' dispatch to a handler.\n'
744-
) in excepts.__doc__
746+
'dispatch to a handler.\n'
747+
) in testlines
745748

746749
def idx(a):
747750
"""idx docstring

toolz/tests/test_inspect_args.py

+19-2
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 toolz
67
from toolz.functoolz import (curry, is_valid_args, is_partial_args, is_arity,
78
num_required_args, has_varargs, has_keywords)
@@ -482,6 +483,22 @@ 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)),)
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+
487504
assert num_required_args(Wrapped) == 1

0 commit comments

Comments
 (0)