예제 #1
0
def test_nested_list_parser() -> None:
    tree = ET.fromstring('''
    <constant type="list">
        <elemType type="list">
            <elemType type="double" />
        </elemType>
    </constant>
    ''')
    t = parser.parse_type(tree)
    assert (t == ast.ListType(ast.ListType('double')))
예제 #2
0
        </elemType>
    </constant>
    ''')
    t = parser.parse_type(tree)
    assert (t == ast.ListType(ast.ListType('double')))


constant_parser_data = [
    ('<const name="Variable" type="string" doc="documentation"><string>value</string></const>',
     ast.Constant(name='Variable',
                  type_='string',
                  doc='documentation',
                  value=None)),
    ('<const name="Variable" type="list" doc="documentation"><elemType type="double" /><list /></const>',
     ast.Constant(name='Variable',
                  type_=ast.ListType('double'),
                  doc='documentation',
                  value=None))
]


@pytest.mark.parametrize('input,expected', constant_parser_data)
def test_constant_parser(input: str, expected: ast.Constant) -> None:
    tree = ET.fromstring(input)
    c = parser.parse_constant(tree)
    assert (c == expected)


def test_namespace_parser() -> None:
    tree = ET.fromstring('<namespace name="cl" value="tutorial" />')
    n = parser.parse_namespace(tree)
예제 #3
0
def make_list_test_data(valueType: str) -> typing.Tuple[str, ast.Type]:
    return (
        f'<constant type="list"><elemType type="{valueType}" /> </constant>',
        ast.ListType(valueType))
예제 #4
0
def parse_list_type(root: ET.Element) -> ast.ListType:
    value_node = root.find('elemType')
    assert (value_node is not None)
    return ast.ListType(valueType=parse_type(value_node))