-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_callbacks.py
46 lines (40 loc) · 1.28 KB
/
test_callbacks.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
41
42
43
44
45
46
from __future__ import annotations
from contextlib import ExitStack as does_not_raise # noqa: N813
import pytest
from pytask_parallel.backends import PARALLEL_BACKENDS
from pytask_parallel.callbacks import n_workers_callback
from pytask_parallel.callbacks import parallel_backend_callback
@pytest.mark.unit
@pytest.mark.parametrize(
"value, expectation",
[
(0, pytest.raises(ValueError)),
(1, does_not_raise()),
(2, does_not_raise()),
("auto", does_not_raise()),
("asdad", pytest.raises(ValueError)),
(None, does_not_raise()),
("None", does_not_raise()),
("none", does_not_raise()),
("1", does_not_raise()),
("1.1", pytest.raises(ValueError)),
],
)
def test_n_workers_callback(value, expectation):
with expectation:
n_workers_callback(value)
@pytest.mark.unit
@pytest.mark.parametrize(
"value, expectation",
[
(1, pytest.raises(ValueError)),
("asdad", pytest.raises(ValueError)),
(None, does_not_raise()),
("None", does_not_raise()),
("none", does_not_raise()),
]
+ [(i, does_not_raise()) for i in PARALLEL_BACKENDS],
)
def test_parallel_backend_callback(value, expectation):
with expectation:
parallel_backend_callback(value)