コード例 #1
0
ファイル: test_enum.py プロジェクト: blampe/thriftrw-python
def test_compile_duplicate_names(parse):
    enum_ast = parse('enum DupeEnum { A, B, A }')

    with pytest.raises(ThriftCompilerError) as exc_info:
        EnumTypeSpec.compile(enum_ast)

    assert 'DupeEnum.A' in str(exc_info)
    assert 'has duplicates' in str(exc_info)
コード例 #2
0
ファイル: test_enum.py プロジェクト: thriftrw/thriftrw-python
def test_compile_duplicate_names(parse):
    enum_ast = parse('enum DupeEnum { A, B, A }')

    with pytest.raises(ThriftCompilerError) as exc_info:
        EnumTypeSpec.compile(enum_ast)

    assert 'DupeEnum.A' in str(exc_info)
    assert 'has duplicates' in str(exc_info)
コード例 #3
0
ファイル: test_enum.py プロジェクト: blampe/thriftrw-python
def test_compile_values_collide(parse):
    enum_ast = parse('enum Foo { A, B, C = 0, D }')
    spec = EnumTypeSpec.compile(enum_ast)

    assert spec.items == {'A': 0, 'B': 1, 'C': 0, 'D': 1}
    assert set(spec.values_to_names[0]) == set(['A', 'C'])
    assert set(spec.values_to_names[1]) == set(['B', 'D'])
コード例 #4
0
ファイル: test_enum.py プロジェクト: thriftrw/thriftrw-python
def test_compile_values_collide(parse):
    enum_ast = parse('enum Foo { A, B, C = 0, D }')
    spec = EnumTypeSpec.compile(enum_ast)

    assert spec.items == {'A': 0, 'B': 1, 'C': 0, 'D': 1}
    assert set(spec.values_to_names[0]) == set(['A', 'C'])
    assert set(spec.values_to_names[1]) == set(['B', 'D'])
コード例 #5
0
def test_compile_values_collide():
    with pytest.raises(ThriftCompilerError) as exc_info:
        EnumTypeSpec(
            'TestEnum',
            {
                'A': 1,
                'B': 5,
                'C': 1
            },
        )

    assert 'Enums items cannot share values' in str(exc_info)
コード例 #6
0
ファイル: test_enum.py プロジェクト: blampe/thriftrw-python
def test_compile_implicit_and_explicit_values(parse):
    enum_ast = parse('enum CombinationEnum { A = 1, B, C = 5, D, E }')

    spec = EnumTypeSpec.compile(enum_ast)
    assert spec.name == 'CombinationEnum'
    assert spec.items == {'A': 1, 'B': 2, 'C': 5, 'D': 6, 'E': 7}
コード例 #7
0
ファイル: test_enum.py プロジェクト: blampe/thriftrw-python
def test_compile_explicit_values(parse):
    enum_ast = parse('enum ExplicitEnum { A = 1, B = 5, C = 3 }')

    spec = EnumTypeSpec.compile(enum_ast)
    assert spec.name == 'ExplicitEnum'
    assert spec.items == {'A': 1, 'B': 5, 'C': 3}
コード例 #8
0
ファイル: test_enum.py プロジェクト: blampe/thriftrw-python
def test_compile_implicit_values(parse):
    enum_ast = parse('enum ImplicitEnum { A, B, C }')

    spec = EnumTypeSpec.compile(enum_ast)
    assert spec.name == 'ImplicitEnum'
    assert spec.items == {'A': 0, 'B': 1, 'C': 2}
コード例 #9
0
ファイル: test_enum.py プロジェクト: thriftrw/thriftrw-python
def test_compile_implicit_and_explicit_values(parse):
    enum_ast = parse('enum CombinationEnum { A = 1, B, C = 5, D, E }')

    spec = EnumTypeSpec.compile(enum_ast)
    assert spec.name == 'CombinationEnum'
    assert spec.items == {'A': 1, 'B': 2, 'C': 5, 'D': 6, 'E': 7}
コード例 #10
0
ファイル: test_enum.py プロジェクト: thriftrw/thriftrw-python
def test_compile_explicit_values(parse):
    enum_ast = parse('enum ExplicitEnum { A = 1, B = 5, C = 3 }')

    spec = EnumTypeSpec.compile(enum_ast)
    assert spec.name == 'ExplicitEnum'
    assert spec.items == {'A': 1, 'B': 5, 'C': 3}
コード例 #11
0
ファイル: test_enum.py プロジェクト: thriftrw/thriftrw-python
def test_compile_implicit_values(parse):
    enum_ast = parse('enum ImplicitEnum { A, B, C }')

    spec = EnumTypeSpec.compile(enum_ast)
    assert spec.name == 'ImplicitEnum'
    assert spec.items == {'A': 0, 'B': 1, 'C': 2}