mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-28 20:44:01 +03:00
cfadd8c3fa
* Add implementation and typing stub * Add unit tests * Update demo example * Add typing tests * Update changelog * Update docs * Add tests for an empty environment variable * Improve wording in di_in_python.rst * Update wording in changelog and docs * Update doc blocks
32 lines
997 B
Python
32 lines
997 B
Python
from pathlib import Path
|
|
from dependency_injector import providers
|
|
|
|
|
|
# Test 1: to check the getattr
|
|
config1 = providers.Configuration()
|
|
provider1 = providers.Factory(dict, a=config1.a)
|
|
|
|
# Test 2: to check the from_*() method
|
|
config2 = providers.Configuration()
|
|
config2.from_dict({})
|
|
config2.from_ini("config.ini")
|
|
config2.from_ini(Path("config.ini"))
|
|
|
|
config2.from_yaml("config.yml")
|
|
config2.from_yaml(Path("config.yml"))
|
|
|
|
config2.from_env("ENV", "default")
|
|
config2.from_env("ENV", as_=int, default=123)
|
|
config2.from_env("ENV", as_=float, required=True)
|
|
config2.from_env("ENV", as_=lambda env: str(env))
|
|
|
|
# Test 3: to check as_*() methods
|
|
config3 = providers.Configuration()
|
|
int3: providers.Callable[int] = config3.option.as_int()
|
|
float3: providers.Callable[float] = config3.option.as_float()
|
|
int3_custom: providers.Callable[int] = config3.option.as_(int)
|
|
|
|
# Test 4: to check required() method
|
|
config4 = providers.Configuration()
|
|
option4: providers.ConfigurationOption = config4.option.required()
|