Add tests

This commit is contained in:
Roman Mogylatov 2022-01-29 22:51:42 -05:00
parent 21f98a4e83
commit ddf1eb29e8
5 changed files with 71 additions and 4 deletions

View File

@ -3,7 +3,7 @@
import sys
from dependency_injector import providers, errors
from pytest import raises
from pytest import raises, mark
from .common import example
@ -29,6 +29,20 @@ def test_set_provides_returns_():
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():
provider = providers.Callable(example)
assert isinstance(provider.provided, providers.ProvidedInstance)

View File

@ -31,6 +31,17 @@ def test_set_provides_returns_self():
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
async def test_call_with_positional_args():
provider = providers.Coroutine(example, 1, 2, 3, 4)

View File

@ -3,7 +3,7 @@
import sys
from dependency_injector import providers, errors
from pytest import raises
from pytest import raises, mark
from .common import Example
@ -29,6 +29,20 @@ def test_set_provides_returns_():
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():
class ExampleProvider(providers.Factory):
provided_type = Example

View File

@ -4,7 +4,7 @@ import sys
from typing import Any
from dependency_injector import containers, providers, resources, errors
from pytest import raises
from pytest import raises, mark
def init_fn(*args, **kwargs):
@ -27,6 +27,20 @@ def test_set_provides_returns_():
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():
provider = providers.Resource(init_fn)
assert isinstance(provider.provided, providers.ProvidedInstance)

View File

@ -3,7 +3,7 @@
import sys
from dependency_injector import providers, errors
from pytest import fixture, raises
from pytest import fixture, raises, mark
from .common import Example
@ -49,6 +49,20 @@ def test_set_provides_returns_self(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):
class ExampleProvider(singleton_cls):
provided_type = Example