def test_sequence(): """Collects each Effectful result into a list.""" effs = [Effect("a"), Effect("b"), Effect("c")] dispatcher = [("a", lambda i: "Ei"), ("b", lambda i: "Bee"), ("c", lambda i: "Cee")] eff = sequence(effs) result = perform_sequence(dispatcher, eff) assert result == ["Ei", "Bee", "Cee"]
def test_sequence(): """Collects each Effectful result into a list.""" effs = [Effect("a"), Effect("b"), Effect("c")] dispatcher = [ ("a", lambda i: "Ei"), ("b", lambda i: "Bee"), ("c", lambda i: "Cee"), ] eff = sequence(effs) result = perform_sequence(dispatcher, eff) assert result == ["Ei", "Bee", "Cee"]
def test_sequence(): """Collects each Effectful result into a list.""" effs = [Effect('a'), Effect('b'), Effect('c')] dispatcher = [ ('a', lambda i: 'Ei'), ('b', lambda i: 'Bee'), ('c', lambda i: 'Cee'), ] eff = sequence(effs) result = perform_sequence(dispatcher, eff) assert result == ['Ei', 'Bee', 'Cee']
def test_sequence(): """Collects each Effectful result into a list.""" effs = [Effect('a'), Effect('b'), Effect('c')] dispatcher = SequenceDispatcher([ ('a', lambda i: 'Ei'), ('b', lambda i: 'Bee'), ('c', lambda i: 'Cee'), ]) eff = sequence(effs) with dispatcher.consume(): result = sync_perform(_base_and(dispatcher), eff) assert result == ['Ei', 'Bee', 'Cee']
def test_sequence_error(): """ Allows :obj:`FoldError` to be raised when an Effect fails. The list accumulated so far is the `accumulator` value in the :obj:`FoldError`. """ effs = [Effect("a"), Effect(Error(ZeroDivisionError("foo"))), Effect("c")] dispatcher = [("a", lambda i: "Ei")] eff = sequence(effs) with raises(FoldError) as excinfo: perform_sequence(dispatcher, eff) assert excinfo.value.accumulator == ["Ei"] assert excinfo.value.wrapped_exception[0] is ZeroDivisionError assert str(excinfo.value.wrapped_exception[1]) == "foo"
def test_sequence_error(): """ Allows :obj:`FoldError` to be raised when an Effect fails. The list accumulated so far is the `accumulator` value in the :obj:`FoldError`. """ effs = [Effect("a"), Effect(Error(ZeroDivisionError("foo"))), Effect("c")] dispatcher = [("a", lambda i: "Ei")] eff = sequence(effs) with raises(FoldError) as excinfo: perform_sequence(dispatcher, eff) assert excinfo.value.accumulator == ["Ei"] assert_that(excinfo.value.wrapped_exception, MatchesException(ZeroDivisionError("foo")))
def test_sequence_error(): """ Allows :obj:`FoldError` to be raised when an Effect fails. The list accumulated so far is the `accumulator` value in the :obj:`FoldError`. """ effs = [Effect('a'), Effect(Error(ZeroDivisionError('foo'))), Effect('c')] dispatcher = [('a', lambda i: 'Ei')] eff = sequence(effs) with raises(FoldError) as excinfo: perform_sequence(dispatcher, eff) assert excinfo.value.accumulator == ['Ei'] assert excinfo.value.wrapped_exception[0] is ZeroDivisionError assert str(excinfo.value.wrapped_exception[1]) == 'foo'
def test_sequence_empty(): """Returns an empty list when there are no Effects.""" assert sync_perform(base_dispatcher, sequence([])) == []