Skip to content

Commit d9e9e3f

Browse files
committed
Fix tests.
1. Always setting __wrapped__ means we needed a slightly different assertion. 2. Support python <3.7 in the test suite.
1 parent 5fc7b1c commit d9e9e3f

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

tests/issue_85_module.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
from dataclasses import dataclass
2-
3-
41
def forwardref_method(foo: "ForwardRef", bar: str) -> "ForwardRef":
5-
return foo.x + bar
2+
return ForwardRef(foo.x + bar)
63

74

8-
@dataclass
95
class ForwardRef:
10-
x: str = "default"
6+
x: str
7+
def __init__(self, x="default"):
8+
self.x = x

tests/test_issues.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def wrapper(foo):
181181
def second_wrapper(foo, bar):
182182
return wrapper(foo) + bar
183183

184-
assert second_wrapper.__wrapped__ is a
184+
assert second_wrapper.__wrapped__ is wrapper
185185
assert "bar" in inspect.signature(second_wrapper).parameters
186186
assert second_wrapper(1, -1) == 0
187187

@@ -254,20 +254,23 @@ def test_issue_77_async_generator_partial():
254254
assert asyncio.get_event_loop().run_until_complete(asyncio.ensure_future(f_partial().__anext__())) == 1
255255

256256

257+
258+
@pytest.mark.skipif(sys.version_info < (3, 3), reason="Tests PEP 367 behavior, which was introduced in python 3.3.")
257259
def test_issue_85_wrapped_forwardref_annotation():
258260
import typing
259261
from . import issue_85_module
260262

261263
@wraps(issue_85_module.forwardref_method, remove_args=["bar"])
262-
def decorated(*args, **kwargs):
263-
return issue_85_module.forwardref_method(*args, **kwargs, bar="x")
264+
def wrapper(**kwargs):
265+
kwargs["bar"] = "x" # python 2 syntax to prevent syntax error.
266+
return issue_85_module.forwardref_method(**kwargs)
264267

265268
# Make sure the wrapper function works as expected
266-
assert decorated(issue_85_module.ForwardRef()) == "defaultx"
269+
assert wrapper(issue_85_module.ForwardRef()).x == "defaultx"
267270

268271
# Check that the type hints of the wrapper are ok with the forward reference correctly resolved
269272
expected_annotations = {
270273
"foo": issue_85_module.ForwardRef,
271274
"return": issue_85_module.ForwardRef,
272275
}
273-
assert typing.get_type_hints(decorated) == expected_annotations
276+
assert typing.get_type_hints(wrapper) == expected_annotations

0 commit comments

Comments
 (0)