| Total Complexity | 3 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from typing import Optional, ClassVar |
||
| 2 | |||
| 3 | from lagom import Container |
||
| 4 | from lagom.environment import Env |
||
| 5 | |||
| 6 | |||
| 7 | class MyEnv(Env): |
||
| 8 | example_value: Optional[str] |
||
| 9 | |||
| 10 | |||
| 11 | class MyEnvWithPrefix(Env): |
||
| 12 | PREFIX: ClassVar = "APPNAME" |
||
| 13 | example_value: str |
||
| 14 | |||
| 15 | |||
| 16 | def test_env_can_be_loaded(container: Container): |
||
| 17 | assert isinstance(container.resolve(MyEnv), MyEnv) |
||
| 18 | |||
| 19 | |||
| 20 | def test_defined_env_variables_are_loaded_automatically( |
||
| 21 | monkeypatch, container: Container |
||
| 22 | ): |
||
| 23 | monkeypatch.setenv("EXAMPLE_VALUE", "from the environment") |
||
| 24 | env = container.resolve(MyEnv) |
||
| 25 | assert env.example_value == "from the environment" |
||
| 26 | |||
| 27 | |||
| 28 | def test_envs_can_have_a_prefix(monkeypatch, container: Container): |
||
| 29 | monkeypatch.setenv("APPNAME_EXAMPLE_VALUE", "from the environment with a prefix") |
||
| 30 | env = container.resolve(MyEnvWithPrefix) |
||
| 31 | assert env.example_value == "from the environment with a prefix" |
||
| 32 |