forked from Bogdanp/django_dramatiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_utils.py
29 lines (24 loc) · 825 Bytes
/
test_utils.py
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
import os
import pytest
from django_dramatiq.utils import getenv_int
@pytest.mark.parametrize("value, default, expected", (
("42", None, 42),
("invalid", 69, 69),
("invalid", None, ValueError),
("invalid", lambda: 96, 96),
(None, 19, 19),
(None, lambda: 78, 78),
(None, "hello", "hello"), # returned default is not checked to be an int
(None, lambda: "world", "world") # idem
))
def test_getenv_int(value, default, expected):
varname = "TEST_ENV_20250204"
if value is not None:
os.environ[varname] = value
else:
os.environ.pop(varname, None)
if isinstance(expected, type) and issubclass(expected, Exception):
with pytest.raises(expected):
getenv_int(varname, default)
else:
assert getenv_int(varname, default) == expected