Пример #1
0
def test_compile_with_duplicate_field_ids(parse):
    with pytest.raises(ThriftCompilerError) as exc_info:
        UnionTypeSpec.compile(
            parse('union Foo { 1: string bar; 1: i32 baz }')
        )
    assert 'Field ID "1" of union "Foo"' in str(exc_info)
    assert 'has already been used' in str(exc_info)
Пример #2
0
def test_compile_with_duplicate_names(parse):
    with pytest.raises(ThriftCompilerError) as exc_info:
        UnionTypeSpec.compile(
            parse('union Foo { 1: string bar; 2: i32 bar }')
        )

    assert 'Field "bar" of union "Foo"' in str(exc_info)
    assert 'has duplicates' in str(exc_info)
Пример #3
0
def test_compile_with_optional_or_required(parse):
    spec = UnionTypeSpec.compile(parse('union Foo { 1: optional string bar }'))
    assert not spec.fields[0].required

    with pytest.raises(ThriftCompilerError) as exc_info:
        UnionTypeSpec.compile(parse('union Foo { 1: required string bar }'))

    assert 'Field "bar" of union "Foo"' in str(exc_info)
    assert 'is "required".' in str(exc_info)
Пример #4
0
def test_compile_with_optional_or_required(parse):
    spec = UnionTypeSpec.compile(
        parse('union Foo { 1: optional string bar }')
    )
    assert not spec.fields[0].required

    with pytest.raises(ThriftCompilerError) as exc_info:
        UnionTypeSpec.compile(parse('union Foo { 1: required string bar }'))

    assert 'Field "bar" of union "Foo"' in str(exc_info)
    assert 'is "required".' in str(exc_info)
Пример #5
0
def test_compile_with_optional_or_required(parse):
    with pytest.raises(ThriftCompilerError) as exc_info:
        UnionTypeSpec.compile(parse("union Foo { 1: optional string bar }"))

    assert 'Field "bar" of union "Foo"' in str(exc_info)
    assert 'is "optional".' in str(exc_info)

    with pytest.raises(ThriftCompilerError) as exc_info:
        UnionTypeSpec.compile(parse("union Foo { 1: required string bar }"))

    assert 'Field "bar" of union "Foo"' in str(exc_info)
    assert 'is "required".' in str(exc_info)
Пример #6
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))),
    ]
Пример #7
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))),
    ]
Пример #8
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))),
    ]
Пример #9
0
def test_compile_with_duplicate_names(parse):
    with pytest.raises(ThriftCompilerError) as exc_info:
        UnionTypeSpec.compile(parse('union Foo { 1: string bar; 2: i32 bar }'))

    assert 'Field "bar" of union "Foo"' in str(exc_info)
    assert 'has duplicates' in str(exc_info)
Пример #10
0
def test_compile_with_duplicate_field_ids(parse):
    with pytest.raises(ThriftCompilerError) as exc_info:
        UnionTypeSpec.compile(parse('union Foo { 1: string bar; 1: i32 baz }'))
    assert 'Field ID "1" of union "Foo"' in str(exc_info)
    assert 'has already been used' in str(exc_info)
Пример #11
0
def test_compile_with_default_value(parse):
    with pytest.raises(ThriftCompilerError) as exc_info:
        UnionTypeSpec.compile(parse('union Foo { 1: string bar = "baz" }'))

    assert 'Field "bar" of union "Foo"' in str(exc_info)
    assert 'has a default value' in str(exc_info)
Пример #12
0
def test_compile_without_field_id(parse):
    with pytest.raises(ThriftCompilerError) as exc_info:
        UnionTypeSpec.compile(parse('union Primitive { string foo }'))

    assert 'Please specify the numeric ID for the field' in str(exc_info)
Пример #13
0
def test_compile_with_default_value(parse):
    with pytest.raises(ThriftCompilerError) as exc_info:
        UnionTypeSpec.compile(parse('union Foo { 1: string bar = "baz" }'))

    assert 'Field "bar" of union "Foo"' in str(exc_info)
    assert 'has a default value' in str(exc_info)
Пример #14
0
def test_compile_without_field_id(parse):
    with pytest.raises(ThriftCompilerError) as exc_info:
        UnionTypeSpec.compile(parse('union Primitive { string foo }'))

    assert 'Please specify the numeric ID for the field' in str(exc_info)