mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-28 12:33:59 +03:00
Add tests
This commit is contained in:
parent
21f98a4e83
commit
ddf1eb29e8
|
@ -3,7 +3,7 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from dependency_injector import providers, errors
|
from dependency_injector import providers, errors
|
||||||
from pytest import raises
|
from pytest import raises, mark
|
||||||
|
|
||||||
from .common import example
|
from .common import example
|
||||||
|
|
||||||
|
@ -29,6 +29,20 @@ def test_set_provides_returns_():
|
||||||
assert provider.set_provides(object) is provider
|
assert provider.set_provides(object) is provider
|
||||||
|
|
||||||
|
|
||||||
|
@mark.parametrize(
|
||||||
|
"str_name,cls",
|
||||||
|
[
|
||||||
|
("dependency_injector.providers.Factory", providers.Factory),
|
||||||
|
("builtins.list", list),
|
||||||
|
("list", list),
|
||||||
|
(".common.example", example),
|
||||||
|
("test_is_provider", test_is_provider),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_set_provides_string_imports(str_name, cls):
|
||||||
|
assert providers.Callable(str_name).provides is cls
|
||||||
|
|
||||||
|
|
||||||
def test_provided_instance_provider():
|
def test_provided_instance_provider():
|
||||||
provider = providers.Callable(example)
|
provider = providers.Callable(example)
|
||||||
assert isinstance(provider.provided, providers.ProvidedInstance)
|
assert isinstance(provider.provided, providers.ProvidedInstance)
|
||||||
|
|
|
@ -31,6 +31,17 @@ def test_set_provides_returns_self():
|
||||||
assert provider.set_provides(example) is provider
|
assert provider.set_provides(example) is provider
|
||||||
|
|
||||||
|
|
||||||
|
@mark.parametrize(
|
||||||
|
"str_name,cls",
|
||||||
|
[
|
||||||
|
(".common.example", example),
|
||||||
|
("example", example),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_set_provides_string_imports(str_name, cls):
|
||||||
|
assert providers.Coroutine(str_name).provides is cls
|
||||||
|
|
||||||
|
|
||||||
@mark.asyncio
|
@mark.asyncio
|
||||||
async def test_call_with_positional_args():
|
async def test_call_with_positional_args():
|
||||||
provider = providers.Coroutine(example, 1, 2, 3, 4)
|
provider = providers.Coroutine(example, 1, 2, 3, 4)
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from dependency_injector import providers, errors
|
from dependency_injector import providers, errors
|
||||||
from pytest import raises
|
from pytest import raises, mark
|
||||||
|
|
||||||
from .common import Example
|
from .common import Example
|
||||||
|
|
||||||
|
@ -29,6 +29,20 @@ def test_set_provides_returns_():
|
||||||
assert provider.set_provides(object) is provider
|
assert provider.set_provides(object) is provider
|
||||||
|
|
||||||
|
|
||||||
|
@mark.parametrize(
|
||||||
|
"str_name,cls",
|
||||||
|
[
|
||||||
|
("dependency_injector.providers.Factory", providers.Factory),
|
||||||
|
("builtins.list", list),
|
||||||
|
("list", list),
|
||||||
|
(".common.Example", Example),
|
||||||
|
("test_is_provider", test_is_provider),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_set_provides_string_imports(str_name, cls):
|
||||||
|
assert providers.Factory(str_name).provides is cls
|
||||||
|
|
||||||
|
|
||||||
def test_init_with_valid_provided_type():
|
def test_init_with_valid_provided_type():
|
||||||
class ExampleProvider(providers.Factory):
|
class ExampleProvider(providers.Factory):
|
||||||
provided_type = Example
|
provided_type = Example
|
||||||
|
|
|
@ -4,7 +4,7 @@ import sys
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from dependency_injector import containers, providers, resources, errors
|
from dependency_injector import containers, providers, resources, errors
|
||||||
from pytest import raises
|
from pytest import raises, mark
|
||||||
|
|
||||||
|
|
||||||
def init_fn(*args, **kwargs):
|
def init_fn(*args, **kwargs):
|
||||||
|
@ -27,6 +27,20 @@ def test_set_provides_returns_():
|
||||||
assert provider.set_provides(init_fn) is provider
|
assert provider.set_provides(init_fn) is provider
|
||||||
|
|
||||||
|
|
||||||
|
@mark.parametrize(
|
||||||
|
"str_name,cls",
|
||||||
|
[
|
||||||
|
("dependency_injector.providers.Factory", providers.Factory),
|
||||||
|
("builtins.list", list),
|
||||||
|
("list", list),
|
||||||
|
(".test_resource_py35.test_is_provider", test_is_provider),
|
||||||
|
("test_is_provider", test_is_provider),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_set_provides_string_imports(str_name, cls):
|
||||||
|
assert providers.Resource(str_name).provides is cls
|
||||||
|
|
||||||
|
|
||||||
def test_provided_instance_provider():
|
def test_provided_instance_provider():
|
||||||
provider = providers.Resource(init_fn)
|
provider = providers.Resource(init_fn)
|
||||||
assert isinstance(provider.provided, providers.ProvidedInstance)
|
assert isinstance(provider.provided, providers.ProvidedInstance)
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from dependency_injector import providers, errors
|
from dependency_injector import providers, errors
|
||||||
from pytest import fixture, raises
|
from pytest import fixture, raises, mark
|
||||||
|
|
||||||
from .common import Example
|
from .common import Example
|
||||||
|
|
||||||
|
@ -49,6 +49,20 @@ def test_set_provides_returns_self(provider):
|
||||||
assert provider.set_provides(object) is provider
|
assert provider.set_provides(object) is provider
|
||||||
|
|
||||||
|
|
||||||
|
@mark.parametrize(
|
||||||
|
"str_name,cls",
|
||||||
|
[
|
||||||
|
("dependency_injector.providers.Factory", providers.Factory),
|
||||||
|
("builtins.list", list),
|
||||||
|
("list", list),
|
||||||
|
(".common.Example", Example),
|
||||||
|
("test_is_provider", test_is_provider),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_set_provides_string_imports(str_name, cls):
|
||||||
|
assert providers.Singleton(str_name).provides is cls
|
||||||
|
|
||||||
|
|
||||||
def test_init_with_valid_provided_type(singleton_cls):
|
def test_init_with_valid_provided_type(singleton_cls):
|
||||||
class ExampleProvider(singleton_cls):
|
class ExampleProvider(singleton_cls):
|
||||||
provided_type = Example
|
provided_type = Example
|
||||||
|
|
Loading…
Reference in New Issue
Block a user