From ddf1eb29e87322ffcba640a05c60d045b2839599 Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Sat, 29 Jan 2022 22:51:42 -0500 Subject: [PATCH] Add tests --- .../providers/callables/test_callable_py2_py3.py | 16 +++++++++++++++- .../providers/coroutines/test_coroutine_py35.py | 11 +++++++++++ .../providers/factories/test_factory_py2_py3.py | 16 +++++++++++++++- .../providers/resource/test_resource_py35.py | 16 +++++++++++++++- .../singleton/test_singleton_py2_py3.py | 16 +++++++++++++++- 5 files changed, 71 insertions(+), 4 deletions(-) diff --git a/tests/unit/providers/callables/test_callable_py2_py3.py b/tests/unit/providers/callables/test_callable_py2_py3.py index fade0a69..4ef351d1 100644 --- a/tests/unit/providers/callables/test_callable_py2_py3.py +++ b/tests/unit/providers/callables/test_callable_py2_py3.py @@ -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) diff --git a/tests/unit/providers/coroutines/test_coroutine_py35.py b/tests/unit/providers/coroutines/test_coroutine_py35.py index 09a8a946..22e794b1 100644 --- a/tests/unit/providers/coroutines/test_coroutine_py35.py +++ b/tests/unit/providers/coroutines/test_coroutine_py35.py @@ -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) diff --git a/tests/unit/providers/factories/test_factory_py2_py3.py b/tests/unit/providers/factories/test_factory_py2_py3.py index ce08006e..e3a1b8f8 100644 --- a/tests/unit/providers/factories/test_factory_py2_py3.py +++ b/tests/unit/providers/factories/test_factory_py2_py3.py @@ -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 diff --git a/tests/unit/providers/resource/test_resource_py35.py b/tests/unit/providers/resource/test_resource_py35.py index 921ec8fa..2f8f60b8 100644 --- a/tests/unit/providers/resource/test_resource_py35.py +++ b/tests/unit/providers/resource/test_resource_py35.py @@ -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) diff --git a/tests/unit/providers/singleton/test_singleton_py2_py3.py b/tests/unit/providers/singleton/test_singleton_py2_py3.py index 49f777fb..c9b5fcb3 100644 --- a/tests/unit/providers/singleton/test_singleton_py2_py3.py +++ b/tests/unit/providers/singleton/test_singleton_py2_py3.py @@ -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