mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-03-27 21:34:22 +03:00
Add test for wiring config invariant
This commit is contained in:
parent
deae475874
commit
40495a961f
|
@ -43,3 +43,7 @@ def test_provided_instance(some_value: int = Provide[Container.service.provided.
|
|||
|
||||
def test_subcontainer_provider(some_value: int = Provide[Container.sub.int_object]):
|
||||
return some_value
|
||||
|
||||
|
||||
def test_config_invariant(some_value: int = Provide[Container.config.option[Container.config.switch]]):
|
||||
return some_value
|
||||
|
|
|
@ -76,3 +76,21 @@ class WiringTest(unittest.TestCase):
|
|||
def test_subcontainer(self):
|
||||
some_value = module.test_subcontainer_provider()
|
||||
self.assertEqual(some_value, 1)
|
||||
|
||||
def test_config_invariant(self):
|
||||
config = {
|
||||
'option': {
|
||||
'a': 1,
|
||||
'b': 2,
|
||||
},
|
||||
'switch': 'a',
|
||||
}
|
||||
self.container.config.from_dict(config)
|
||||
|
||||
with self.container.config.switch.override('a'):
|
||||
value_a = module.test_config_invariant()
|
||||
self.assertEqual(value_a, 1)
|
||||
|
||||
with self.container.config.switch.override('b'):
|
||||
value_b = module.test_config_invariant()
|
||||
self.assertEqual(value_b, 2)
|
||||
|
|
Loading…
Reference in New Issue
Block a user