|
1 | 1 | import functools |
2 | 2 | import pytest |
| 3 | +import re |
3 | 4 | import sys |
4 | 5 |
|
5 | 6 | import makefun |
|
11 | 12 |
|
12 | 13 | PY2 = sys.version_info < (3, ) |
13 | 14 |
|
| 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 | + |
14 | 20 |
|
15 | 21 | def test_doc(): |
16 | 22 | def foo(x, y): |
@@ -41,15 +47,15 @@ def foo(x, y): |
41 | 47 |
|
42 | 48 | sig_actual_call = ref_sig_str.replace("*, ", "") |
43 | 49 |
|
44 | | - assert bar.__doc__ \ |
| 50 | + assert DOCSTRING_NORMALIZE_RE.sub("", bar.__doc__) \ |
45 | 51 | == """<This function is equivalent to 'foo%s', see original 'foo' doc below.> |
46 | 52 |
|
47 | | - a `foo` function |
| 53 | +a `foo` function |
48 | 54 |
|
49 | | - :param x: |
50 | | - :param y: |
51 | | - :return: |
52 | | - """ % sig_actual_call |
| 55 | +:param x: |
| 56 | +:param y: |
| 57 | +:return: |
| 58 | +""" % sig_actual_call |
53 | 59 |
|
54 | 60 |
|
55 | 61 | def test_partial(): |
@@ -78,16 +84,16 @@ def foo(x, y, a): |
78 | 84 |
|
79 | 85 | sig_actual_call = "(x, y='hello', a)" # if PY2 else "(x, *, y='hello', a)" |
80 | 86 |
|
81 | | - assert foo.__doc__.replace("=KW_ONLY_ARG!", "") \ |
| 87 | + assert DOCSTRING_NORMALIZE_RE.sub("", foo.__doc__.replace("=KW_ONLY_ARG!", "")) \ |
82 | 88 | == """<This function is equivalent to 'foo%s', see original 'foo' doc below.> |
83 | 89 |
|
84 | | - a `foo` function |
| 90 | +a `foo` function |
85 | 91 |
|
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 |
91 | 97 |
|
92 | 98 |
|
93 | 99 | def test_issue_57(): |
@@ -127,9 +133,7 @@ def f(b=0): |
127 | 133 | assert m() == -1 |
128 | 134 | assert m.i == 1 |
129 | 135 | # 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__ |
133 | 137 |
|
134 | 138 |
|
135 | 139 | def test_args_order_and_kind(): |
|
0 commit comments