Beispiel #1
0
def test_hash_err_same_type_different_message():
    x = Err(Exception('foo'))
    y = Err(Exception('bar'))

    assert x != y
    assert hash(x) != hash(y)
Beispiel #2
0
def test_hash_err():
    x = Err(Exception('error message'))
    y = Err(Exception('error message'))

    assert x == y
    assert hash(x) == hash(y)
Beispiel #3
0
def test_hash_err_different_type_same_message():
    x = Err(IOError('error message'))
    y = Err(TypeError('error message'))

    assert x != y
    assert hash(x) != hash(y)
Beispiel #4
0
def test_and_with_ok_err():
    x = Ok(2)
    y = Err(Exception('late'))

    assert x.and_(y) == Err(Exception('late'))
Beispiel #5
0
def test_ok_or_else_with_nun():
    x = Nun()

    assert x.ok_or_else(lambda: Exception('error message')) == Err(Exception('error message'))
Beispiel #6
0
def test_err_val_must_be_exception():
    with pytest.raises(Panic):
        Err(0)
Beispiel #7
0
def test_map_with_err():
    x = Err(Exception('error message'))

    assert x.map(lambda x: x**2) == x
Beispiel #8
0
def test_or_else_with_err():
    x = Err(Exception('error message'))

    assert x.or_else(lambda x: Ok(True)) == Ok(True)
Beispiel #9
0
def test_unwrap_with_err():
    x = Err(Exception('error message'))

    with pytest.raises(Panic):
        x.unwrap()
Beispiel #10
0
def test_or_with_ok():
    x = Ok(2)

    assert x.or_(Err(Exception('error message'))) == x
Beispiel #11
0
def test_or_with_err():
    x = Err(Exception('error message'))

    assert x.or_(Ok(5)) == Ok(5)
Beispiel #12
0
def test_and_then_with_err():
    x = Err(Exception('error message'))

    assert x.and_then(lambda x: x + 1) == x
Beispiel #13
0
def test_and_then_with_ok_and_then_err():
    x = Ok(2)

    assert x.and_then(lambda x: Err(Exception(x + 1))) == Err(Exception(3))
Beispiel #14
0
def test_and_with_err_err():
    x = Err(Exception('early'))
    y = Err(Exception('late'))

    assert x.and_(y) == Err(Exception('early'))
Beispiel #15
0
def test_is_err_with_err():
    x = Err(Exception("error message"))

    assert x.is_err()
Beispiel #16
0
def test_unwrap_or_with_err():
    x = Err(Exception('error message'))

    assert x.unwrap_or(0) == 0
Beispiel #17
0
def test_ok_with_err():
    x = Err(Exception("error message"))

    assert x.ok() == Nun()
Beispiel #18
0
def test_unwrap_or_else_with_err():
    x = Err(Exception('error message'))

    assert x.unwrap_or_else(lambda x: x.args[0].upper()) == 'ERROR MESSAGE'
Beispiel #19
0
def test_err_with_err():
    x = Err(Exception("error message"))

    assert x.err() == Some("error message")
Beispiel #20
0
def test_unwrap_err_with_err():
    x = Err(Exception('error message'))

    assert x.unwrap_err().args == Exception('error message').args
Beispiel #21
0
def test_map_err_with_err():
    x = Err(Exception('error message'))

    assert x.map_err(lambda x: Err(type(x)(x.args[0].upper()))) == Err(
        Exception('ERROR MESSAGE'))
Beispiel #22
0
def test_iter_with_err():
    x = Err(Exception('error message'))

    assert list(iter(x)) == []
Beispiel #23
0
def test_and_with_err_ok():
    x = Err(Exception('early'))
    y = Ok(2)

    assert x.and_(y) == Err(Exception('early'))
Beispiel #24
0
def test_ok_or_with_nun():
    x = Nun()

    assert x.ok_or(Exception('error message')) == Err(Exception('error message'))