-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_env_get_bool.py
More file actions
141 lines (125 loc) · 3.92 KB
/
test_env_get_bool.py
File metadata and controls
141 lines (125 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
"""Test the get_bool_env_var function"""
import os
import unittest
from unittest.mock import patch
from env import get_bool_env_var
class TestEnv(unittest.TestCase):
"""Test the get_bool_env_var function"""
@patch.dict(
os.environ,
{
"TEST_BOOL": "true",
},
clear=True,
)
def test_get_bool_env_var_that_exists_and_is_true(self):
"""Test that gets a boolean environment variable that exists and is true"""
result = get_bool_env_var("TEST_BOOL", False)
self.assertTrue(result)
@patch.dict(
os.environ,
{
"TEST_BOOL": "True",
},
clear=True,
)
def test_get_bool_env_var_that_exists_and_is_true_capitalized(self):
"""Test that gets a boolean environment variable with capitalized True"""
result = get_bool_env_var("TEST_BOOL", False)
self.assertTrue(result)
@patch.dict(
os.environ,
{
"TEST_BOOL": "TRUE",
},
clear=True,
)
def test_get_bool_env_var_that_exists_and_is_true_upper(self):
"""Test that gets a boolean environment variable with uppercase TRUE"""
result = get_bool_env_var("TEST_BOOL", False)
self.assertTrue(result)
@patch.dict(
os.environ,
{
"TEST_BOOL": "false",
},
clear=True,
)
def test_get_bool_env_var_that_exists_and_is_false(self):
"""Test that gets a boolean environment variable that exists and is false"""
result = get_bool_env_var("TEST_BOOL", False)
self.assertFalse(result)
@patch.dict(
os.environ,
{
"TEST_BOOL": "nope",
},
clear=True,
)
def test_get_bool_env_var_that_exists_and_is_false_due_to_invalid_value(self):
"""Test that gets a boolean environment variable that exists and is false
due to an invalid value
"""
result = get_bool_env_var("TEST_BOOL", False)
self.assertFalse(result)
@patch.dict(
os.environ,
{
"TEST_BOOL": "",
},
clear=True,
)
def test_get_bool_env_var_that_exists_and_is_empty(self):
"""Test that gets a boolean environment variable that exists but is empty"""
result = get_bool_env_var("TEST_BOOL", False)
self.assertFalse(result)
@patch.dict(
os.environ,
{
"TEST_BOOL": "",
},
clear=True,
)
def test_get_bool_env_var_that_exists_and_is_empty_with_default_true(self):
"""Test that gets a boolean environment variable that is empty with default True"""
result = get_bool_env_var("TEST_BOOL", True)
self.assertTrue(result)
@patch.dict(
os.environ,
{
"TEST_BOOL": "false",
},
clear=True,
)
def test_get_bool_env_var_that_does_not_exist_and_default_value_returns_true(self):
"""Test that gets a boolean environment variable that does not exist
and default value returns: true
"""
result = get_bool_env_var("DOES_NOT_EXIST", True)
self.assertTrue(result)
@patch.dict(
os.environ,
{
"TEST_BOOL": "true",
},
clear=True,
)
def test_get_bool_env_var_that_does_not_exist_and_default_value_returns_false(self):
"""Test that gets a boolean environment variable that does not exist
and default value returns: false
"""
result = get_bool_env_var("DOES_NOT_EXIST", False)
self.assertFalse(result)
@patch.dict(
os.environ,
{
"TEST_BOOL": " true ",
},
clear=True,
)
def test_get_bool_env_var_with_whitespace(self):
"""Test that gets a boolean environment variable with leading/trailing whitespace"""
result = get_bool_env_var("TEST_BOOL", False)
self.assertTrue(result)
if __name__ == "__main__":
unittest.main()