示例#1
0
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"]
示例#2
0
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"]
示例#3
0
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']
示例#4
0
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']
示例#5
0
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"
示例#6
0
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")))
示例#7
0
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'
示例#8
0
def test_sequence_empty():
    """Returns an empty list when there are no Effects."""
    assert sync_perform(base_dispatcher, sequence([])) == []
示例#9
0
def test_sequence_empty():
    """Returns an empty list when there are no Effects."""
    assert sync_perform(base_dispatcher, sequence([])) == []