diff --git a/docs/main/changelog.rst b/docs/main/changelog.rst index e5faa794..bb396b49 100644 --- a/docs/main/changelog.rst +++ b/docs/main/changelog.rst @@ -10,6 +10,7 @@ follows `Semantic versioning`_ Development version ------------------- - Add tests for ``Selector`` provider. +- Add tests for ``ProvidedInstance`` and ``MethodCaller`` providers. - Update Makefile to make Python 3 tests to be a default test command: ``make test``. 4.17.0 diff --git a/tests/unit/providers/test_provided_instance_py2_py3.py b/tests/unit/providers/test_provided_instance_py2_py3.py index ffba4376..814b341b 100644 --- a/tests/unit/providers/test_provided_instance_py2_py3.py +++ b/tests/unit/providers/test_provided_instance_py2_py3.py @@ -10,12 +10,20 @@ class Service: self.value = value self.values = [self.value] - def get_value(self): + def __call__(self): return self.value def __getitem__(self, item): return self.values[item] + def get_value(self): + return self.value + + def get_closure(self): + def closure(): + return self.value + return closure + class Client: def __init__(self, value): @@ -45,6 +53,15 @@ class Container(containers.DeclarativeContainer): Client, value=service.provided.get_value.call(), ) + client_method_closure_call = providers.Factory( + Client, + value=service.provided.get_closure.call().call(), + ) + + client_provided_call = providers.Factory( + Client, + value=service.provided.call(), + ) class ProvidedInstanceTests(unittest.TestCase): @@ -71,6 +88,14 @@ class ProvidedInstanceTests(unittest.TestCase): client = self.container.client_method_call() self.assertEqual(client.value, 'foo') + def test_method_closure_call(self): + client = self.container.client_method_closure_call() + self.assertEqual(client.value, 'foo') + + def test_provided_call(self): + client = self.container.client_provided_call() + self.assertEqual(client.value, 'foo') + def test_call_overridden(self): value = 'bar' with self.container.service.override(Service(value)):