コード例 #1
0
def test_decode_encode(tp_code):
    tp, code = tp_code
    encode = io.encoder(tp)
    decode = io.decoder(tp)
    value = decode(code)
    actual_code = encode(value)
    assert actual_code == code
コード例 #2
0
def program(*types):
    """Program decorator specifying types.

    All but the last type are inputs; the last type is the output type.

    """
    if not types:
        raise SyntaxError('No output type: program{}'.format(types))
    tps_in = types[:-1]
    tp_out = types[-1]
    encoders = map(io.encoder, tps_in)
    decoder = io.decoder(tp_out)
    return lambda fun: Program(encoders, decoder, fun)
コード例 #3
0
def test_decode_error(tp, code):
    decode = io.decoder(tp)
    with pytest.raises(TypeError):
        decode(code)
コード例 #4
0
def test_decode(tp, code, value):
    decode = io.decoder(tp)
    actual_value = decode(code)
    assert actual_value == value