-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_init.py
More file actions
74 lines (50 loc) · 2.13 KB
/
Copy pathtest_init.py
File metadata and controls
74 lines (50 loc) · 2.13 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
import warnings
import httpx
import pytest
from taskbadger import Badger, init
from taskbadger.exceptions import ConfigurationError
from taskbadger.mug import DEFAULT_HTTP_TIMEOUT, _local
@pytest.fixture(autouse=True)
def _reset():
b_global = Badger.current
_local.set(Badger())
yield
_local.set(b_global)
def test_init():
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
init("org", "project", "token", before_create=lambda x: x)
def test_init_import_before_create():
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
init("org", "project", "token", before_create="tests.test_init._before_create")
def test_init_import_before_create_fail():
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
with pytest.raises(ConfigurationError):
init("org", "project", "token", before_create="missing")
def test_init_default_timeout():
_init_token()
assert Badger.current.settings.timeout == DEFAULT_HTTP_TIMEOUT
assert Badger.current.client().get_httpx_client().timeout == httpx.Timeout(DEFAULT_HTTP_TIMEOUT)
def test_init_timeout_override():
_init_token(timeout=30)
assert Badger.current.client().get_httpx_client().timeout == httpx.Timeout(30)
def test_init_timeout_from_env(monkeypatch):
monkeypatch.setenv("TASKBADGER_HTTP_TIMEOUT", "12.5")
_init_token()
assert Badger.current.settings.timeout == 12.5
def test_init_timeout_arg_beats_env(monkeypatch):
monkeypatch.setenv("TASKBADGER_HTTP_TIMEOUT", "12.5")
_init_token(timeout=httpx.Timeout(1, connect=2))
assert Badger.current.client().get_httpx_client().timeout == httpx.Timeout(1, connect=2)
def test_init_timeout_from_env_invalid(monkeypatch):
monkeypatch.setenv("TASKBADGER_HTTP_TIMEOUT", "soon")
with pytest.raises(ConfigurationError):
_init_token()
def _init_token(**kwargs):
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
init("org", "project", "token", **kwargs)
def _before_create(_):
pass