77 ComposedDispatcher , Effect , Error ,
88 base_dispatcher , sync_perform )
99from 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 ])
10+ from effect .testing import perform_sequence
1611
1712
1813def test_fold_effect ():
@@ -22,15 +17,13 @@ def test_fold_effect():
2217 """
2318 effs = [Effect ('a' ), Effect ('b' ), Effect ('c' )]
2419
25- dispatcher = SequenceDispatcher ( [
20+ dispatcher = [
2621 ('a' , lambda i : 'Ei' ),
2722 ('b' , lambda i : 'Bee' ),
2823 ('c' , lambda i : 'Cee' ),
29- ])
24+ ]
3025 eff = fold_effect (operator .add , 'Nil' , effs )
31-
32- with dispatcher .consume ():
33- result = sync_perform (_base_and (dispatcher ), eff )
26+ result = perform_sequence (dispatcher , eff )
3427 assert result == 'NilEiBeeCee'
3528
3629
@@ -50,15 +43,12 @@ def test_fold_effect_errors():
5043 """
5144 effs = [Effect ('a' ), Effect (Error (ZeroDivisionError ('foo' ))), Effect ('c' )]
5245
53- dispatcher = SequenceDispatcher ([
54- ('a' , lambda i : 'Ei' ),
55- ])
46+ dispatcher = [('a' , lambda i : 'Ei' )]
5647
5748 eff = fold_effect (operator .add , 'Nil' , effs )
5849
59- with dispatcher .consume ():
60- with raises (FoldError ) as excinfo :
61- sync_perform (_base_and (dispatcher ), eff )
50+ with raises (FoldError ) as excinfo :
51+ perform_sequence (dispatcher , eff )
6252 assert excinfo .value .accumulator == 'NilEi'
6353 assert excinfo .value .wrapped_exception [0 ] is ZeroDivisionError
6454 assert str (excinfo .value .wrapped_exception [1 ]) == 'foo'
@@ -67,14 +57,11 @@ def test_fold_effect_errors():
6757def test_fold_effect_str ():
6858 """str()ing a FoldError returns useful traceback/exception info."""
6959 effs = [Effect ('a' ), Effect (Error (ZeroDivisionError ('foo' ))), Effect ('c' )]
70- dispatcher = SequenceDispatcher ([
71- ('a' , lambda i : 'Ei' ),
72- ])
60+ dispatcher = [('a' , lambda i : 'Ei' )]
7361
7462 eff = fold_effect (operator .add , 'Nil' , effs )
75- with dispatcher .consume ():
76- with raises (FoldError ) as excinfo :
77- sync_perform (_base_and (dispatcher ), eff )
63+ with raises (FoldError ) as excinfo :
64+ perform_sequence (dispatcher , eff )
7865 assert str (excinfo .value ).startswith (
7966 "<FoldError after accumulating 'NilEi'> Original traceback follows:\n " )
8067 assert str (excinfo .value ).endswith ('ZeroDivisionError: foo' )
@@ -83,15 +70,14 @@ def test_fold_effect_str():
8370def test_sequence ():
8471 """Collects each Effectful result into a list."""
8572 effs = [Effect ('a' ), Effect ('b' ), Effect ('c' )]
86- dispatcher = SequenceDispatcher ( [
73+ dispatcher = [
8774 ('a' , lambda i : 'Ei' ),
8875 ('b' , lambda i : 'Bee' ),
8976 ('c' , lambda i : 'Cee' ),
90- ])
77+ ]
9178 eff = sequence (effs )
9279
93- with dispatcher .consume ():
94- result = sync_perform (_base_and (dispatcher ), eff )
80+ result = perform_sequence (dispatcher , eff )
9581 assert result == ['Ei' , 'Bee' , 'Cee' ]
9682
9783
@@ -107,15 +93,12 @@ def test_sequence_error():
10793 """
10894 effs = [Effect ('a' ), Effect (Error (ZeroDivisionError ('foo' ))), Effect ('c' )]
10995
110- dispatcher = SequenceDispatcher ([
111- ('a' , lambda i : 'Ei' ),
112- ])
96+ dispatcher = [('a' , lambda i : 'Ei' )]
11397
11498 eff = sequence (effs )
11599
116- with dispatcher .consume ():
117- with raises (FoldError ) as excinfo :
118- sync_perform (_base_and (dispatcher ), eff )
100+ with raises (FoldError ) as excinfo :
101+ perform_sequence (dispatcher , eff )
119102 assert excinfo .value .accumulator == ['Ei' ]
120103 assert excinfo .value .wrapped_exception [0 ] is ZeroDivisionError
121104 assert str (excinfo .value .wrapped_exception [1 ]) == 'foo'
0 commit comments