Passed
Branch master (918acb)
by Steve
02:15
created

tests.test_env_wrapper.test_env_can_be_loaded()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 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