Example #1
0
def test_match_ok():
    msg = 'Okdok'
    return_ok = Match(Ok('Success')) \
        .ok(ok_op, msg) \
        .collect()

    assert return_ok == ok_op(msg)
Example #2
0
def test_ok_is_ok():
    ok = Ok('Success')

    assert ok.is_ok() is True
Example #3
0
def test_ok_is_err():
    ok = Ok('Success')

    assert ok.is_err() is False
Example #4
0
def test_ok_expect():
    ok = Ok('Success')

    assert ok.expect('Some err') == 'Success'
Example #5
0
def test_ok_contains_err():
    ok = Ok('Success')

    assert ok.contains_err('Some err') is False
Example #6
0
def test_match_ok_without_arg():
    return_ok = Match(Ok('Success')) \
        .ok(op_without_arg) \
        .collect()

    assert return_ok == op_without_arg()
Example #7
0
def divide(a, b):
    try:
        return Ok(a / b)
    except ZeroDivisionError:
        return Err('Oh no, a ZeroDivisionError just happened')
Example #8
0
def test_ok_unwrap_or():
    ok = Ok('Success')

    assert ok.unwrap_or('Alternative Success') == 'Success'
Example #9
0
def test_ok_repr():
    ok = Ok('Success')

    assert repr(ok) == "Ok('Success')"
Example #10
0
def test_ok_ne():
    ok = Ok('Success')
    ok2 = Ok('Ok return')

    assert ok != 'Success'
    assert ok != ok2
Example #11
0
def test_ok_hash():
    ok = Ok('Success')
    ok1 = Ok('Success')

    assert ok.__hash__() == ok1.__hash__()
Example #12
0
def test_ok_eq():
    ok = Ok('Success')
    ok1 = Ok('Success')

    assert ok == ok1
    assert not (ok == 'Success')
Example #13
0
def test_match_return_none_with_no_op():
    return_ok = Match(Ok('Success')) \
        .ok(None) \
        .collect()

    assert return_ok is None
Example #14
0
def test_match_ok_with_kwargs():
    return_ok = Match(Ok('Success')) \
        .ok(op_with_kwargs, a=1, b=2, c=3, d=4, e=5) \
        .collect()

    assert return_ok == op_with_kwargs()
Example #15
0
def test_match_ok_with_args():
    return_ok = Match(Ok('Success')) \
        .ok(op_with_args, 1, 2, 3, 4, 5) \
        .collect()

    assert return_ok == op_with_args()
Example #16
0
def test_ok_unwrap():
    ok = Ok('Success')

    assert ok.unwrap() == 'Success'
Example #17
0
def test_ok_unwrap_err():
    ok = Ok('Success')

    with pytest.raises(UnwrapErr):
        ok.unwrap_err()
Example #18
0
def test_ok_str():
    ok = Ok('Success')

    assert str(ok) == 'Ok: Success'
Example #19
0
def test_ok_cls():
    ok = Ok('Success')

    assert isinstance(ok, Result) is True
    assert isinstance(ok, Ok) is True
Example #20
0
def test_ok_contains():
    ok = Ok('Success')

    assert ok.contains('Success') is True
Example #21
0
def authenticate(username, password):
    if username == 'ok' and password == 'err':
        user = User(username)
        return Ok(user)

    return Err("You're not allowed here!")
Example #22
0
def test_ok_val():
    ok = Ok('Success')

    assert ok.value == 'Success'