Skip to content

Commit 4514cd0

Browse files
committed
improv: update tests to include non-truthy choice var
1 parent 9fe0d9e commit 4514cd0

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed
Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,42 @@
11
from distutils.util import strtobool
2+
from typing import Any, Union
23

34

4-
def resolve_truthy_env_var_choice(env: str, choice: bool = None) -> bool:
5+
def resolve_truthy_env_var_choice(env: Any, choice: bool = None) -> bool:
6+
""" Pick explicit choice over truthy env value, if available, otherwise return truthy env value
7+
8+
NOTE: Environment variable should be resolved by the caller.
9+
10+
Parameters
11+
----------
12+
env : Any
13+
environment variable actual value
14+
choice : bool
15+
explicit choice
16+
17+
Returns
18+
-------
19+
choice : str
20+
resolved choice as either bool or environment value
21+
"""
522
return choice if choice is not None else strtobool(env)
623

724

8-
def resolve_env_var_choice(env: str, choice: bool = None) -> bool:
25+
def resolve_env_var_choice(env: Any, choice: bool = None) -> Union[bool, Any]:
26+
""" Pick explicit choice over env, if available, otherwise return env value received
27+
28+
NOTE: Environment variable should be resolved by the caller.
29+
30+
Parameters
31+
----------
32+
env : Any
33+
environment variable actual value
34+
choice : bool
35+
explicit choice
36+
37+
Returns
38+
-------
39+
choice : str
40+
resolved choice as either bool or environment value
41+
"""
942
return choice if choice is not None else env
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
from aws_lambda_powertools.shared.functions import resolve_truthy_env_var_choice
1+
from aws_lambda_powertools.shared.functions import resolve_env_var_choice, resolve_truthy_env_var_choice
22

33

44
def test_resolve_env_var_choice_explicit_wins_over_env_var():
55
assert resolve_truthy_env_var_choice(env="true", choice=False) is False
6+
assert resolve_env_var_choice(env="something", choice=False) is False
67

78

89
def test_resolve_env_var_choice_env_wins_over_absent_explicit():
910
assert resolve_truthy_env_var_choice(env="true") == 1
11+
assert resolve_env_var_choice(env="something") == "something"

0 commit comments

Comments
 (0)