Ejemplo n.º 1
0
def test_is_err_with_ok():
    x = Ok(-3)

    assert not x.is_err()
Ejemplo n.º 2
0
def test_iter_with_ok():
    x = Ok(2)

    assert list(iter(x)) == [2]
Ejemplo n.º 3
0
def test_hash_ok():
    x = Ok(2)
    y = Ok(2)

    assert x == y
    assert hash(x) == hash(y)
Ejemplo n.º 4
0
def test_and_with_ok_err():
    x = Ok(2)
    y = Err(Exception('late'))

    assert x.and_(y) == Err(Exception('late'))
Ejemplo n.º 5
0
def test_ok_or_else_with_some():
    x = Some(2)

    assert x.ok_or_else(lambda: Exception('error message')) == Ok(2)
Ejemplo n.º 6
0
def test_err_with_ok():
    x = Ok(2)

    assert x.err() == Nun()
Ejemplo n.º 7
0
def test_map_err_with_ok():
    x = Ok(2)

    assert x.map_err(lambda x: type(x)(x.args[0].upper())) == x
Ejemplo n.º 8
0
def test_or_else_with_ok():
    x = Ok(2)

    assert x.or_else(lambda x: Ok(True)) == x
Ejemplo n.º 9
0
def test_or_else_with_err():
    x = Err(Exception('error message'))

    assert x.or_else(lambda x: Ok(True)) == Ok(True)
Ejemplo n.º 10
0
def test_or_with_ok():
    x = Ok(2)

    assert x.or_(Err(Exception('error message'))) == x
Ejemplo n.º 11
0
def test_or_with_err():
    x = Err(Exception('error message'))

    assert x.or_(Ok(5)) == Ok(5)
Ejemplo n.º 12
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))
Ejemplo n.º 13
0
def test_and_then_with_ok():
    x = Ok(2)

    assert x.and_then(lambda x: Ok(x**2)) == Ok(4)
Ejemplo n.º 14
0
def test_is_ok_with_ok():
    x = Ok(-3)

    assert x.is_ok()
Ejemplo n.º 15
0
def test_hash_ok_not_eq():
    x = Ok(2)
    y = Ok(3)

    assert x != y
    assert hash(x) != hash(y)
Ejemplo n.º 16
0
def test_unwrap_with_ok():
    x = Ok(2)

    assert x.unwrap() == 2
Ejemplo n.º 17
0
def test_ok_with_ok():
    x = Ok(2)

    assert x.ok() == Some(2)
Ejemplo n.º 18
0
def test_unwrap_or_with_ok():
    x = Ok(2)

    assert x.unwrap_or(0) == 2
Ejemplo n.º 19
0
def test_map_with_ok():
    x = Ok(2)

    assert x.map(lambda x: x**2) == Ok(4)
Ejemplo n.º 20
0
def test_unwrap_or_else_with_ok():
    x = Ok(2)

    assert x.unwrap_or_else(lambda x: x.args[0].upper()) == 2
Ejemplo n.º 21
0
def test_and_with_ok_ok():
    x = Ok(2)
    y = Ok(3)

    assert x.and_(y) == Ok(3)
Ejemplo n.º 22
0
def test_unwrap_err_with_ok():
    x = Ok(2)

    with pytest.raises(Panic):
        x.unwrap_err()
Ejemplo n.º 23
0
def test_and_with_err_ok():
    x = Err(Exception('early'))
    y = Ok(2)

    assert x.and_(y) == Err(Exception('early'))
Ejemplo n.º 24
0
def test_ok_or_with_some():
    x = Some(2)

    assert x.ok_or(Exception('error message')) == Ok(2)