-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_impartial.py
More file actions
64 lines (39 loc) · 1.3 KB
/
Copy pathtest_impartial.py
File metadata and controls
64 lines (39 loc) · 1.3 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
from functools import partial
from impartial import impartial
def f(x: int, y: int, z: int = 0) -> int:
return x + 2*y + z
def test_simple_call_args():
assert impartial(f, 1)(2) == f(1, 2)
def test_simple_call_kwargs():
assert impartial(f, y=2)(x=1) == f(1, 2)
def test_simple_call_empty():
assert impartial(f, 1, y=2)() == f(1, 2)
def test_decorator():
@impartial
def f(x, y):
return x + 2*y
assert f.with_y(2)(1) == 5
def test_func():
assert impartial(f, 1).func is f
def test_with_kwargs():
assert impartial(f, 1).with_z(3)(2) == f(1, 2, 3)
def test_multiple_with_kwargs():
assert impartial(f, 1).with_z(3).with_y(2)() == f(1, 2, 3)
def test_with_kwargs_override():
assert impartial(f, 1, 2).with_z(3).with_z(4)() == f(1, 2, 4)
def test_nested_impartial():
imp = impartial(f, x=1, y=2)
imp = impartial(imp, x=2)
imp = impartial(imp, x=3)
assert imp() == f(3, 2)
assert not isinstance(imp.func, impartial)
assert imp.func is f
def test_nested_partial():
imp = partial(f, x=1, y=2)
imp = partial(imp, x=2)
imp = impartial(imp, x=3)
assert imp() == f(3, 2)
assert not isinstance(imp.func, partial)
assert imp.func is f
def test_configure():
assert impartial(f, 1, z=2).configure(2, z=3)() == f(1, 2, 3)