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

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

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

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

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

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

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

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

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

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

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

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

    assert return_ok is None
示例#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()
示例#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()
示例#16
0
def test_ok_unwrap():
    ok = Ok('Success')

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

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

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

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

    assert ok.contains('Success') is True
示例#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!")
示例#22
0
def test_ok_val():
    ok = Ok('Success')

    assert ok.value == 'Success'