33
44from pytest import raises
55
6- from effect import (
7- ComposedDispatcher , Effect , Error ,
8- base_dispatcher , sync_perform )
6+ from effect import Effect , Error , base_dispatcher , sync_perform
97from 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
169
1710
1811def test_fold_effect ():
@@ -22,15 +15,13 @@ def test_fold_effect():
2215 """
2316 effs = [Effect ('a' ), Effect ('b' ), Effect ('c' )]
2417
25- dispatcher = SequenceDispatcher ( [
18+ dispatcher = [
2619 ('a' , lambda i : 'Ei' ),
2720 ('b' , lambda i : 'Bee' ),
2821 ('c' , lambda i : 'Cee' ),
29- ])
22+ ]
3023 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 )
3425 assert result == 'NilEiBeeCee'
3526
3627
@@ -50,15 +41,12 @@ def test_fold_effect_errors():
5041 """
5142 effs = [Effect ('a' ), Effect (Error (ZeroDivisionError ('foo' ))), Effect ('c' )]
5243
53- dispatcher = SequenceDispatcher ([
54- ('a' , lambda i : 'Ei' ),
55- ])
44+ dispatcher = [('a' , lambda i : 'Ei' )]
5645
5746 eff = fold_effect (operator .add , 'Nil' , effs )
5847
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 )
6250 assert excinfo .value .accumulator == 'NilEi'
6351 assert excinfo .value .wrapped_exception [0 ] is ZeroDivisionError
6452 assert str (excinfo .value .wrapped_exception [1 ]) == 'foo'
@@ -67,14 +55,11 @@ def test_fold_effect_errors():
6755def test_fold_effect_str ():
6856 """str()ing a FoldError returns useful traceback/exception info."""
6957 effs = [Effect ('a' ), Effect (Error (ZeroDivisionError ('foo' ))), Effect ('c' )]
70- dispatcher = SequenceDispatcher ([
71- ('a' , lambda i : 'Ei' ),
72- ])
58+ dispatcher = [('a' , lambda i : 'Ei' )]
7359
7460 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 )
7863 assert str (excinfo .value ).startswith (
7964 "<FoldError after accumulating 'NilEi'> Original traceback follows:\n " )
8065 assert str (excinfo .value ).endswith ('ZeroDivisionError: foo' )
@@ -83,15 +68,14 @@ def test_fold_effect_str():
8368def test_sequence ():
8469 """Collects each Effectful result into a list."""
8570 effs = [Effect ('a' ), Effect ('b' ), Effect ('c' )]
86- dispatcher = SequenceDispatcher ( [
71+ dispatcher = [
8772 ('a' , lambda i : 'Ei' ),
8873 ('b' , lambda i : 'Bee' ),
8974 ('c' , lambda i : 'Cee' ),
90- ])
75+ ]
9176 eff = sequence (effs )
9277
93- with dispatcher .consume ():
94- result = sync_perform (_base_and (dispatcher ), eff )
78+ result = perform_sequence (dispatcher , eff )
9579 assert result == ['Ei' , 'Bee' , 'Cee' ]
9680
9781
@@ -107,15 +91,12 @@ def test_sequence_error():
10791 """
10892 effs = [Effect ('a' ), Effect (Error (ZeroDivisionError ('foo' ))), Effect ('c' )]
10993
110- dispatcher = SequenceDispatcher ([
111- ('a' , lambda i : 'Ei' ),
112- ])
94+ dispatcher = [('a' , lambda i : 'Ei' )]
11395
11496 eff = sequence (effs )
11597
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 )
119100 assert excinfo .value .accumulator == ['Ei' ]
120101 assert excinfo .value .wrapped_exception [0 ] is ZeroDivisionError
121102 assert str (excinfo .value .wrapped_exception [1 ]) == 'foo'
0 commit comments