Skip to content

Commit 76d31cd

Browse files
author
Sylvain MARIE
committed
Merge branch 'py313' of https://github.com/mgorny/python-makefun into feature/102_py313
2 parents d31a2c5 + 0e6d70f commit 76d31cd

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

tests/test_partial_and_macros.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import functools
22
import pytest
3+
import re
34
import sys
45

56
import makefun
@@ -11,6 +12,11 @@
1112

1213
PY2 = sys.version_info < (3, )
1314

15+
# Python 3.13 dedents docstrings, earlier versions just strip initial
16+
# whitespace. Use a regexp to get a consistently dedented docstring
17+
# for comparison across Python versions.
18+
DOCSTRING_NORMALIZE_RE = re.compile(r"^ +", re.MULTILINE)
19+
1420

1521
def test_doc():
1622
def foo(x, y):
@@ -41,15 +47,15 @@ def foo(x, y):
4147

4248
sig_actual_call = ref_sig_str.replace("*, ", "")
4349

44-
assert bar.__doc__ \
50+
assert DOCSTRING_NORMALIZE_RE.sub("", bar.__doc__) \
4551
== """<This function is equivalent to 'foo%s', see original 'foo' doc below.>
4652
47-
a `foo` function
53+
a `foo` function
4854
49-
:param x:
50-
:param y:
51-
:return:
52-
""" % sig_actual_call
55+
:param x:
56+
:param y:
57+
:return:
58+
""" % sig_actual_call
5359

5460

5561
def test_partial():
@@ -78,16 +84,16 @@ def foo(x, y, a):
7884

7985
sig_actual_call = "(x, y='hello', a)" # if PY2 else "(x, *, y='hello', a)"
8086

81-
assert foo.__doc__.replace("=KW_ONLY_ARG!", "") \
87+
assert DOCSTRING_NORMALIZE_RE.sub("", foo.__doc__.replace("=KW_ONLY_ARG!", "")) \
8288
== """<This function is equivalent to 'foo%s', see original 'foo' doc below.>
8389
84-
a `foo` function
90+
a `foo` function
8591
86-
:param x:
87-
:param y:
88-
:param a:
89-
:return:
90-
""" % sig_actual_call
92+
:param x:
93+
:param y:
94+
:param a:
95+
:return:
96+
""" % sig_actual_call
9197

9298

9399
def test_issue_57():
@@ -127,9 +133,7 @@ def f(b=0):
127133
assert m() == -1
128134
assert m.i == 1
129135
# the doc remains untouched in create_function as opposed to wraps, this is normal
130-
assert m.__doc__ == """partial(func, *args, **keywords) - new function with partial application
131-
of the given arguments and keywords.
132-
"""
136+
assert m.__doc__ == functools.partial.__doc__
133137

134138

135139
def test_args_order_and_kind():

0 commit comments

Comments
 (0)