/pypy/module/pyexpat/test/test_build.py
https://bitbucket.org/pypy/pypy/ · Python · 35 lines · 30 code · 5 blank · 0 comment · 4 complexity · 97fa02f1e399a5df434d124a6ca4ee9c MD5 · raw file
- from rpython.translator.translator import TranslationContext
- from rpython.translator.c.genc import CStandaloneBuilder
- from rpython.annotator.listdef import s_list_of_strings
- from rpython.rtyper.lltypesystem import rffi, lltype
- from rpython.rtyper.tool.rffi_platform import CompilationError
- import os
- import py
- try:
- import pyexpat
- except ImportError:
- py.test.skip("No module expat")
- try:
- from pypy.module.pyexpat import interp_pyexpat
- except (ImportError, CompilationError):
- py.test.skip("Expat not installed")
- def test_build():
- def entry_point(argv):
- parser = interp_pyexpat.XML_ParserCreate("test")
- interp_pyexpat.XML_ParserFree(parser)
- res = interp_pyexpat.XML_ErrorString(3)
- os.write(1, rffi.charp2str(res))
- return 0
- t = TranslationContext()
- t.buildannotator().build_types(entry_point, [s_list_of_strings])
- t.buildrtyper().specialize()
- builder = CStandaloneBuilder(t, entry_point, t.config)
- builder.generate_source()
- builder.compile()
- data = builder.cmdexec()
- assert data == pyexpat.ErrorString(3)