forked from Delgan/loguru
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_defaults.py
40 lines (33 loc) · 1.12 KB
/
test_defaults.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
30
31
32
33
34
35
36
37
38
39
40
import pytest
from loguru._defaults import env
@pytest.mark.parametrize("value", ["test", ""])
def test_string(value, monkeypatch):
key = "VALID_STRING"
monkeypatch.setenv(key, value)
assert env(key, str) == value
@pytest.mark.parametrize("value", ['y', '1', 'TRUE'])
def test_bool_positive(value, monkeypatch):
key = "VALID_BOOL_POS"
monkeypatch.setenv(key, value)
assert env(key, bool) == True
@pytest.mark.parametrize("value", ['NO', '0', 'false'])
def test_bool_negative(value, monkeypatch):
key = "VALID_BOOL_NEG"
monkeypatch.setenv(key, value)
assert env(key, bool) == False
def test_int(monkeypatch):
key = "VALID_INT"
monkeypatch.setenv(key, "42")
assert env(key, int) == 42
@pytest.mark.parametrize("value", ["", "a"])
def test_invalid_int(value, monkeypatch):
key = "INVALID_INT"
monkeypatch.setenv(key, value)
with pytest.raises(ValueError):
env(key, int)
@pytest.mark.parametrize("value", ["", "a"])
def test_invalid_bool(value, monkeypatch):
key = "INVALID_BOOL"
monkeypatch.setenv(key, value)
with pytest.raises(ValueError):
env(key, bool)