Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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))),
    ]
Beispiel #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))),
    ]
Beispiel #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))),
    ]
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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)