Exemple #1
0
def test_arg_parser() -> None:
    tree = ET.fromstring(
        '<arg name="num1" field-id="1" type="i32" doc="document" required="optional" />'
    )
    expected = ast.Field(
        name='num1', key=1, required='optional', doc='document', type_='i32')
    assert (parser.parse_arg(tree) == expected)
Exemple #2
0
def _parse_field_with_tag(tag: str, root: ET.Element) -> ast.Field:
    assert (root.tag == tag)
    return ast.Field(name=root.attrib['name'],
                     key=int(root.attrib['field-id']),
                     doc=root.get('doc', ''),
                     required=root.get('required', 'required'),
                     type_=parse_type(root))
Exemple #3
0
def test_field_parser() -> None:
    tree = ET.fromstring(
        '<field name="op" field-id="3" type="id" type-module="Example" type-id="Operation" />'
    )
    expected = ast.Field(name='op',
                         key=3,
                         type_=ast.ReferenceType(module='Example',
                                                 name='Operation'))
    assert (parser.parse_field(tree) == expected)
Exemple #4
0
def test_method_parser() -> None:
    tree = ET.fromstring('''
    <method name="zip" oneway="true" doc="oneway doc">
        <arg name="logid" field-id="1" type="i32" />
        <returns type="void" />
        <throws name="ouch" field-id="1" type="id" type-module="Example" type-id="InvalidOperation" />
    </method>
    ''')
    expected = ast.Function(
        name='zip',
        oneway=True,
        doc='oneway doc',
        returnType='void',
        arguments=[ast.Field(name='logid', key=1, type_='i32')],
        exceptions=[
            ast.Field(name='ouch',
                      key=1,
                      type_=ast.ReferenceType(name='InvalidOperation',
                                              module='Example'))
        ])
    assert (parser.parse_method(tree) == expected)