-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pipe.py
More file actions
48 lines (33 loc) · 894 Bytes
/
test_pipe.py
File metadata and controls
48 lines (33 loc) · 894 Bytes
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
import pytest
from src.pipe import pipe, CompositionError
def test_pipe() -> None:
result = pipe(
5,
add_1,
divide_by_2
)
assert result == divide_by_2(add_1(5))
def test_pipe_errors_with_wrong_types() -> None:
with pytest.raises(CompositionError): # Runtime error
_ = pipe(
5,
add_1,
divide_by_2,
celebrate # <-- wrong input type!
)
def test_pipe_errors_with_wrong_number_of_args() -> None:
with pytest.raises(CompositionError):
_ = pipe(
5,
add_1,
subtract, # <-- it takes two args!
divide_by_2
)
def add_1(x: int) -> int:
return x + 1
def divide_by_2(y: int) -> float:
return y / 2
def celebrate(z: str) -> str:
return f"Congrats {z}!"
def subtract(x: int, y: int) -> int:
return x - y