Пример #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)
Пример #2
0
def test_hash_err():
    x = Err(Exception('error message'))
    y = Err(Exception('error message'))

    assert x == y
    assert hash(x) == hash(y)
Пример #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)
Пример #4
0
def test_and_with_ok_err():
    x = Ok(2)
    y = Err(Exception('late'))

    assert x.and_(y) == Err(Exception('late'))
Пример #5
0
def test_ok_or_else_with_nun():
    x = Nun()

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

    assert x.map(lambda x: x**2) == x
Пример #8
0
def test_or_else_with_err():
    x = Err(Exception('error message'))

    assert x.or_else(lambda x: Ok(True)) == Ok(True)
Пример #9
0
def test_unwrap_with_err():
    x = Err(Exception('error message'))

    with pytest.raises(Panic):
        x.unwrap()
Пример #10
0
def test_or_with_ok():
    x = Ok(2)

    assert x.or_(Err(Exception('error message'))) == x
Пример #11
0
def test_or_with_err():
    x = Err(Exception('error message'))

    assert x.or_(Ok(5)) == Ok(5)
Пример #12
0
def test_and_then_with_err():
    x = Err(Exception('error message'))

    assert x.and_then(lambda x: x + 1) == x
Пример #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))
Пример #14
0
def test_and_with_err_err():
    x = Err(Exception('early'))
    y = Err(Exception('late'))

    assert x.and_(y) == Err(Exception('early'))
Пример #15
0
def test_is_err_with_err():
    x = Err(Exception("error message"))

    assert x.is_err()
Пример #16
0
def test_unwrap_or_with_err():
    x = Err(Exception('error message'))

    assert x.unwrap_or(0) == 0
Пример #17
0
def test_ok_with_err():
    x = Err(Exception("error message"))

    assert x.ok() == Nun()
Пример #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'
Пример #19
0
def test_err_with_err():
    x = Err(Exception("error message"))

    assert x.err() == Some("error message")
Пример #20
0
def test_unwrap_err_with_err():
    x = Err(Exception('error message'))

    assert x.unwrap_err().args == Exception('error message').args
Пример #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'))
Пример #22
0
def test_iter_with_err():
    x = Err(Exception('error message'))

    assert list(iter(x)) == []
Пример #23
0
def test_and_with_err_ok():
    x = Err(Exception('early'))
    y = Ok(2)

    assert x.and_(y) == Err(Exception('early'))
Пример #24
0
def test_ok_or_with_nun():
    x = Nun()

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