Exemple #1
0
def test_flat_map_error():
    map_in = f_return(0)

    # This one should fail...
    mapped = f_flat_map(map_in, div10)

    # Now map it through an error handler
    mapped = f_flat_map(mapped, error_fn=lambda ex: f_return(str(ex)))

    result = mapped.result()
    assert "division" in result
Exemple #2
0
def test_flat_map_error_fn_raises():
    map_in = f_return(0)

    # This one should fail...
    mapped = f_flat_map(map_in, div10)

    # Now map it through an error handler
    mapped = f_flat_map(mapped, error_fn=raise_str)

    ex = mapped.exception()
    assert "division" in str(ex)
    assert "oops, an error" in str(ex)
Exemple #3
0
def test_flat_map_error():
    with pytest.raises(TypeError):
        f_flat_map("a", lambda x: x)

    with pytest.raises(TypeError):
        f_flat_map(future="a", fn=lambda x: x)
Exemple #4
0
def test_flat_map():
    map_in = f_return(10)
    mapped = f_flat_map(map_in, div10)
    assert mapped.result() == 1
Exemple #5
0
def test_flat_map_nothing():
    map_in = f_return(10)
    mapped = f_flat_map(map_in)
    assert mapped.result() == 10