diff --git a/tests/unit/wiring/module.py b/tests/unit/wiring/module.py index a8df06f1..8ac15f8c 100644 --- a/tests/unit/wiring/module.py +++ b/tests/unit/wiring/module.py @@ -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 diff --git a/tests/unit/wiring/test_wiring_py36.py b/tests/unit/wiring/test_wiring_py36.py index a4d44a4d..1d008a0c 100644 --- a/tests/unit/wiring/test_wiring_py36.py +++ b/tests/unit/wiring/test_wiring_py36.py @@ -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)