3
3
4
4
from pytest import raises
5
5
6
- from effect import (
7
- ComposedDispatcher , Effect , Error ,
8
- base_dispatcher , sync_perform )
6
+ from effect import Effect , Error , base_dispatcher , sync_perform
9
7
from effect .fold import FoldError , fold_effect , sequence
10
- from effect .testing import SequenceDispatcher
11
-
12
-
13
- def _base_and (dispatcher ):
14
- """Compose base_dispatcher onto the given dispatcher."""
15
- return ComposedDispatcher ([dispatcher , base_dispatcher ])
8
+ from effect .testing import perform_sequence
16
9
17
10
18
11
def test_fold_effect ():
@@ -22,15 +15,13 @@ def test_fold_effect():
22
15
"""
23
16
effs = [Effect ('a' ), Effect ('b' ), Effect ('c' )]
24
17
25
- dispatcher = SequenceDispatcher ( [
18
+ dispatcher = [
26
19
('a' , lambda i : 'Ei' ),
27
20
('b' , lambda i : 'Bee' ),
28
21
('c' , lambda i : 'Cee' ),
29
- ])
22
+ ]
30
23
eff = fold_effect (operator .add , 'Nil' , effs )
31
-
32
- with dispatcher .consume ():
33
- result = sync_perform (_base_and (dispatcher ), eff )
24
+ result = perform_sequence (dispatcher , eff )
34
25
assert result == 'NilEiBeeCee'
35
26
36
27
@@ -50,15 +41,12 @@ def test_fold_effect_errors():
50
41
"""
51
42
effs = [Effect ('a' ), Effect (Error (ZeroDivisionError ('foo' ))), Effect ('c' )]
52
43
53
- dispatcher = SequenceDispatcher ([
54
- ('a' , lambda i : 'Ei' ),
55
- ])
44
+ dispatcher = [('a' , lambda i : 'Ei' )]
56
45
57
46
eff = fold_effect (operator .add , 'Nil' , effs )
58
47
59
- with dispatcher .consume ():
60
- with raises (FoldError ) as excinfo :
61
- sync_perform (_base_and (dispatcher ), eff )
48
+ with raises (FoldError ) as excinfo :
49
+ perform_sequence (dispatcher , eff )
62
50
assert excinfo .value .accumulator == 'NilEi'
63
51
assert excinfo .value .wrapped_exception [0 ] is ZeroDivisionError
64
52
assert str (excinfo .value .wrapped_exception [1 ]) == 'foo'
@@ -67,14 +55,11 @@ def test_fold_effect_errors():
67
55
def test_fold_effect_str ():
68
56
"""str()ing a FoldError returns useful traceback/exception info."""
69
57
effs = [Effect ('a' ), Effect (Error (ZeroDivisionError ('foo' ))), Effect ('c' )]
70
- dispatcher = SequenceDispatcher ([
71
- ('a' , lambda i : 'Ei' ),
72
- ])
58
+ dispatcher = [('a' , lambda i : 'Ei' )]
73
59
74
60
eff = fold_effect (operator .add , 'Nil' , effs )
75
- with dispatcher .consume ():
76
- with raises (FoldError ) as excinfo :
77
- sync_perform (_base_and (dispatcher ), eff )
61
+ with raises (FoldError ) as excinfo :
62
+ perform_sequence (dispatcher , eff )
78
63
assert str (excinfo .value ).startswith (
79
64
"<FoldError after accumulating 'NilEi'> Original traceback follows:\n " )
80
65
assert str (excinfo .value ).endswith ('ZeroDivisionError: foo' )
@@ -83,15 +68,14 @@ def test_fold_effect_str():
83
68
def test_sequence ():
84
69
"""Collects each Effectful result into a list."""
85
70
effs = [Effect ('a' ), Effect ('b' ), Effect ('c' )]
86
- dispatcher = SequenceDispatcher ( [
71
+ dispatcher = [
87
72
('a' , lambda i : 'Ei' ),
88
73
('b' , lambda i : 'Bee' ),
89
74
('c' , lambda i : 'Cee' ),
90
- ])
75
+ ]
91
76
eff = sequence (effs )
92
77
93
- with dispatcher .consume ():
94
- result = sync_perform (_base_and (dispatcher ), eff )
78
+ result = perform_sequence (dispatcher , eff )
95
79
assert result == ['Ei' , 'Bee' , 'Cee' ]
96
80
97
81
@@ -107,15 +91,12 @@ def test_sequence_error():
107
91
"""
108
92
effs = [Effect ('a' ), Effect (Error (ZeroDivisionError ('foo' ))), Effect ('c' )]
109
93
110
- dispatcher = SequenceDispatcher ([
111
- ('a' , lambda i : 'Ei' ),
112
- ])
94
+ dispatcher = [('a' , lambda i : 'Ei' )]
113
95
114
96
eff = sequence (effs )
115
97
116
- with dispatcher .consume ():
117
- with raises (FoldError ) as excinfo :
118
- sync_perform (_base_and (dispatcher ), eff )
98
+ with raises (FoldError ) as excinfo :
99
+ perform_sequence (dispatcher , eff )
119
100
assert excinfo .value .accumulator == ['Ei' ]
120
101
assert excinfo .value .wrapped_exception [0 ] is ZeroDivisionError
121
102
assert str (excinfo .value .wrapped_exception [1 ]) == 'foo'
0 commit comments