def test_validate():
    spec = ListTypeSpec(prim_spec.BinaryTypeSpec)
    spec.validate([b'a'])
    spec.validate([u'a'])

    with pytest.raises(TypeError):
        spec.validate(42)
Exemple #2
0
def test_compile(parse):
    spec = UnionTypeSpec.compile(
        parse('''union Foo {
            1: binary b
            2: string s
            3: i32 i
            4: list<Foo> l
        }'''))

    assert spec.name == 'Foo'
    assert spec.fields == [
        FieldSpec(id=1,
                  name='b',
                  spec=prim_spec.BinaryTypeSpec,
                  required=False),
        FieldSpec(id=2, name='s', spec=prim_spec.TextTypeSpec, required=False),
        FieldSpec(id=3, name='i', spec=prim_spec.I32TypeSpec, required=False),
        FieldSpec(id=4,
                  name='l',
                  required=False,
                  spec=ListTypeSpec(TypeReference('Foo', 5))),
    ]
Exemple #3
0
def slist(value):
    return ListTypeSpec(value)
def test_mapper(parse):
    ast = parse('list<binary>')
    spec = type_spec_or_ref(ast)
    assert spec == ListTypeSpec(prim_spec.BinaryTypeSpec)