python-dependency-injector/examples/providers/configuration/configuration_value.py
Roman Mogylatov dbbf5fdcf1
462 Config.from_value() (#465)
* Implement .from_value() method for config provider

* Add tests for config.from_value() method

* Add example for config.from_value()

* Add docs

* Update changelog
2021-06-13 22:05:29 -04:00

25 lines
641 B
Python

"""`Configuration` provider values loading example."""
from datetime import date
from dependency_injector import containers, providers
class Container(containers.DeclarativeContainer):
config = providers.Configuration()
if __name__ == '__main__':
container = Container()
container.config.option1.from_value(date(2021, 6, 13))
container.config.option2.from_value(date(2021, 6, 14))
assert container.config() == {
'option1': date(2021, 6, 13),
'option2': date(2021, 6, 14),
}
assert container.config.option1() == date(2021, 6, 13)
assert container.config.option2() == date(2021, 6, 14)