mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-05-23 05:56:19 +03:00
Add tests and implement cache reset for configuration option
This commit is contained in:
parent
989aaecd6d
commit
6f05e99f0a
File diff suppressed because it is too large
Load Diff
|
@ -1489,8 +1489,13 @@ cdef class ConfigurationOption(Provider):
|
|||
|
||||
def reset_cache(self):
|
||||
self.__cache = UNDEFINED
|
||||
for child in self.__children.values():
|
||||
child.reset_cache()
|
||||
|
||||
for provider in self.__children.values():
|
||||
provider.reset_cache()
|
||||
|
||||
for provider in self.overrides:
|
||||
if isinstance(provider, (Configuration, ConfigurationOption)):
|
||||
provider.reset_cache()
|
||||
|
||||
def update(self, value):
|
||||
"""Set configuration options.
|
||||
|
|
|
@ -416,6 +416,58 @@ class ConfigLinkingTests(unittest.TestCase):
|
|||
self.assertEqual(services.config.value(), 'services2')
|
||||
self.assertEqual(services.value_getter(), 'services2')
|
||||
|
||||
def test_reset_overriding_cache(self):
|
||||
class Core(containers.DeclarativeContainer):
|
||||
config = providers.Configuration()
|
||||
|
||||
greetings = providers.Factory(str, config.greeting)
|
||||
|
||||
class Application(containers.DeclarativeContainer):
|
||||
config = providers.Configuration()
|
||||
|
||||
core = providers.Container(
|
||||
Core,
|
||||
config=config,
|
||||
)
|
||||
|
||||
greetings = providers.Factory(str, config.greeting)
|
||||
|
||||
container = Application()
|
||||
|
||||
container.config.set('greeting', 'Hello World')
|
||||
self.assertEqual(container.greetings(), 'Hello World')
|
||||
self.assertEqual(container.core.greetings(), 'Hello World')
|
||||
|
||||
container.config.set('greeting', 'Hello Bob')
|
||||
self.assertEqual(container.greetings(), 'Hello Bob')
|
||||
self.assertEqual(container.core.greetings(), 'Hello Bob')
|
||||
|
||||
def test_reset_overriding_cache_for_option(self):
|
||||
class Core(containers.DeclarativeContainer):
|
||||
config = providers.Configuration()
|
||||
|
||||
greetings = providers.Factory(str, config.greeting)
|
||||
|
||||
class Application(containers.DeclarativeContainer):
|
||||
config = providers.Configuration()
|
||||
|
||||
core = providers.Container(
|
||||
Core,
|
||||
config=config.option,
|
||||
)
|
||||
|
||||
greetings = providers.Factory(str, config.option.greeting)
|
||||
|
||||
container = Application()
|
||||
|
||||
container.config.set('option.greeting', 'Hello World')
|
||||
self.assertEqual(container.greetings(), 'Hello World')
|
||||
self.assertEqual(container.core.greetings(), 'Hello World')
|
||||
|
||||
container.config.set('option.greeting', 'Hello Bob')
|
||||
self.assertEqual(container.greetings(), 'Hello Bob')
|
||||
self.assertEqual(container.core.greetings(), 'Hello Bob')
|
||||
|
||||
|
||||
class ConfigFromIniTests(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user