Skip to content

Commit ddf1eb2

Browse files
committed
Add tests
1 parent 21f98a4 commit ddf1eb2

File tree

5 files changed

+71
-4
lines changed

5 files changed

+71
-4
lines changed

tests/unit/providers/callables/test_callable_py2_py3.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44

55
from dependency_injector import providers, errors
6-
from pytest import raises
6+
from pytest import raises, mark
77

88
from .common import example
99

@@ -29,6 +29,20 @@ def test_set_provides_returns_():
2929
assert provider.set_provides(object) is provider
3030

3131

32+
@mark.parametrize(
33+
"str_name,cls",
34+
[
35+
("dependency_injector.providers.Factory", providers.Factory),
36+
("builtins.list", list),
37+
("list", list),
38+
(".common.example", example),
39+
("test_is_provider", test_is_provider),
40+
],
41+
)
42+
def test_set_provides_string_imports(str_name, cls):
43+
assert providers.Callable(str_name).provides is cls
44+
45+
3246
def test_provided_instance_provider():
3347
provider = providers.Callable(example)
3448
assert isinstance(provider.provided, providers.ProvidedInstance)

tests/unit/providers/coroutines/test_coroutine_py35.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ def test_set_provides_returns_self():
3131
assert provider.set_provides(example) is provider
3232

3333

34+
@mark.parametrize(
35+
"str_name,cls",
36+
[
37+
(".common.example", example),
38+
("example", example),
39+
],
40+
)
41+
def test_set_provides_string_imports(str_name, cls):
42+
assert providers.Coroutine(str_name).provides is cls
43+
44+
3445
@mark.asyncio
3546
async def test_call_with_positional_args():
3647
provider = providers.Coroutine(example, 1, 2, 3, 4)

tests/unit/providers/factories/test_factory_py2_py3.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44

55
from dependency_injector import providers, errors
6-
from pytest import raises
6+
from pytest import raises, mark
77

88
from .common import Example
99

@@ -29,6 +29,20 @@ def test_set_provides_returns_():
2929
assert provider.set_provides(object) is provider
3030

3131

32+
@mark.parametrize(
33+
"str_name,cls",
34+
[
35+
("dependency_injector.providers.Factory", providers.Factory),
36+
("builtins.list", list),
37+
("list", list),
38+
(".common.Example", Example),
39+
("test_is_provider", test_is_provider),
40+
],
41+
)
42+
def test_set_provides_string_imports(str_name, cls):
43+
assert providers.Factory(str_name).provides is cls
44+
45+
3246
def test_init_with_valid_provided_type():
3347
class ExampleProvider(providers.Factory):
3448
provided_type = Example

tests/unit/providers/resource/test_resource_py35.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Any
55

66
from dependency_injector import containers, providers, resources, errors
7-
from pytest import raises
7+
from pytest import raises, mark
88

99

1010
def init_fn(*args, **kwargs):
@@ -27,6 +27,20 @@ def test_set_provides_returns_():
2727
assert provider.set_provides(init_fn) is provider
2828

2929

30+
@mark.parametrize(
31+
"str_name,cls",
32+
[
33+
("dependency_injector.providers.Factory", providers.Factory),
34+
("builtins.list", list),
35+
("list", list),
36+
(".test_resource_py35.test_is_provider", test_is_provider),
37+
("test_is_provider", test_is_provider),
38+
],
39+
)
40+
def test_set_provides_string_imports(str_name, cls):
41+
assert providers.Resource(str_name).provides is cls
42+
43+
3044
def test_provided_instance_provider():
3145
provider = providers.Resource(init_fn)
3246
assert isinstance(provider.provided, providers.ProvidedInstance)

tests/unit/providers/singleton/test_singleton_py2_py3.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44

55
from dependency_injector import providers, errors
6-
from pytest import fixture, raises
6+
from pytest import fixture, raises, mark
77

88
from .common import Example
99

@@ -49,6 +49,20 @@ def test_set_provides_returns_self(provider):
4949
assert provider.set_provides(object) is provider
5050

5151

52+
@mark.parametrize(
53+
"str_name,cls",
54+
[
55+
("dependency_injector.providers.Factory", providers.Factory),
56+
("builtins.list", list),
57+
("list", list),
58+
(".common.Example", Example),
59+
("test_is_provider", test_is_provider),
60+
],
61+
)
62+
def test_set_provides_string_imports(str_name, cls):
63+
assert providers.Singleton(str_name).provides is cls
64+
65+
5266
def test_init_with_valid_provided_type(singleton_cls):
5367
class ExampleProvider(singleton_cls):
5468
provided_type = Example

0 commit comments

Comments
 (0)