def test_struct_visitor(self): ast = header_to_ast('../../../../../clib/tests/check_isti_sqlite.h') data = [] def save(name, node): data.append(name) data.append(node) StructVisitor(save).visit(ast) assert data[0] == 'foo', data[0] assert isinstance(data[1], Struct), data[1]
def test_ast_to_structs(self): ast = header_to_ast('../../../../../clib/tests/check_isti_sqlite.h') structs = ast_to_structs(ast) assert len(structs) == 1, structs assert 'foo' in [struct['sname'] for struct in structs], structs fields = structs[0]['fields'] assert len(fields) == 3, fields for field in fields: assert field['fname'] in ('id', 'bar', 'baz'), field assert field['fname'] != 'id' or field['type'] == 'int' assert field['fname'] != 'bar' or field['type'] == 'int' assert field['fname'] != 'baz' or (field['type'] == 'char' and field['pointer'])
def run(files, prefix='corm'): for infile in files: root = splitext(infile)[0] outfile = root + '.%s.' % prefix ast = header_to_ast(infile) structs = ast_to_structs(ast) with open(outfile + 'h', 'w') as out: generate_h_preamble(out, original=infile, root=root.replace(sep, '_')) for struct in structs: generate_h(struct, out, prefix=prefix) generate_h_postamble(out) with open(outfile + 'c', 'w') as out: generate_c_preamble(out, header=outfile+'h') for struct in structs: generate_c(struct, out, prefix=prefix) with open(outfile + 'sql', 'w') as out: for struct in structs: generate_sql(struct, out)
def test_generate(self): ast = header_to_ast('../../../../../clib/tests/check_isti_sqlite.h') structs = ast_to_structs(ast) for struct in structs: generate(struct) assert False
def test_parse_isti_str(self): ast = header_to_ast('../../../../../clib/tests/check_isti_sqlite.h') ast.show()