mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-02-11 17:10:57 +03:00
Add test
This commit is contained in:
parent
6554b25431
commit
957a467229
49
tests/unit/wiring/test_inject_and_wraps_decorator_py36.py
Normal file
49
tests/unit/wiring/test_inject_and_wraps_decorator_py36.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
"""Test that @functools.wraps decorator works properly with the wiring.
|
||||
|
||||
See issue #453 for details: https://github.com/ets-labs/python-dependency-injector/issues/454
|
||||
"""
|
||||
|
||||
import functools
|
||||
|
||||
from dependency_injector.wiring import inject, Provide
|
||||
from pytest import fixture
|
||||
|
||||
from samples.wiring.container import Container
|
||||
|
||||
|
||||
@fixture
|
||||
def container():
|
||||
container = Container()
|
||||
yield container
|
||||
container.unwire()
|
||||
|
||||
|
||||
def decorator1(func):
|
||||
@functools.wraps(func)
|
||||
@inject
|
||||
def wrapper(value1: str = Provide[Container.config.value1]):
|
||||
result = func()
|
||||
return result + value1
|
||||
return wrapper
|
||||
|
||||
|
||||
def decorator2(func):
|
||||
@functools.wraps(func)
|
||||
@inject
|
||||
def wrapper(value2: str = Provide[Container.config.value2]):
|
||||
result = func()
|
||||
return result + value2
|
||||
return wrapper
|
||||
|
||||
|
||||
@decorator1
|
||||
@decorator2
|
||||
def sample():
|
||||
return 2
|
||||
|
||||
|
||||
def test_wraps(container: Container):
|
||||
container.wire(modules=[__name__])
|
||||
container.config.from_dict({"value1": 42, "value2": 15})
|
||||
|
||||
assert sample() == 2+42+15
|
Loading…
Reference in New Issue
Block a user