mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 09:36:48 +03:00
Add tests for .provided & .call()
This commit is contained in:
parent
288284aa9c
commit
c9ab7d540d
|
@ -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
|
||||
|
|
|
@ -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)):
|
||||
|
|
Loading…
Reference in New Issue
Block a user