<s> import sys <EOL> import py <EOL> from cffi import FFI <EOL> from cffi import recompiler , ffiplatform , VerificationMissing <EOL> from testing . udir import udir <EOL> def setup_module ( mod ) : <EOL> SRC = """<STR_LIT>""" <EOL> tmpdir = udir . join ( '<STR_LIT>' ) <EOL> tmpdir . ensure ( dir = <NUM_LIT:1> ) <EOL> c_file = tmpdir . join ( '<STR_LIT>' ) <EOL> c_file . write ( SRC ) <EOL> ext = ffiplatform . get_extension ( <EOL> str ( c_file ) , <EOL> '<STR_LIT>' , <EOL> export_symbols = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> outputfilename = ffiplatform . compile ( str ( tmpdir ) , ext ) <EOL> mod . extmod = outputfilename <EOL> mod . tmpdir = tmpdir <EOL> ffi = FFI ( ) <EOL> ffi . cdef ( """<STR_LIT>""" ) <EOL> ffi . set_source ( '<STR_LIT>' , None ) <EOL> ffi . emit_python_code ( str ( tmpdir . join ( '<STR_LIT>' ) ) ) <EOL> mod . original_ffi = ffi <EOL> sys . path . insert ( <NUM_LIT:0> , str ( tmpdir ) ) <EOL> def test_constant ( ) : <EOL> from re_python_pysrc import ffi <EOL> assert ffi . integer_const ( '<STR_LIT>' ) == - <NUM_LIT> <EOL> assert ffi . integer_const ( '<STR_LIT>' ) == - <NUM_LIT> <EOL> def test_large_constant ( ) : <EOL> from re_python_pysrc import ffi <EOL> assert ffi . integer_const ( '<STR_LIT>' ) == <NUM_LIT> <EOL> assert ffi . integer_const ( '<STR_LIT>' ) == - <NUM_LIT> <EOL> def test_function ( ) : <EOL> import _cffi_backend <EOL> from re_python_pysrc import ffi <EOL> lib = ffi . dlopen ( extmod ) <EOL> assert lib . add42 ( - <NUM_LIT:10> ) == <NUM_LIT:32> <EOL> assert type ( lib . add42 ) is _cffi_backend . FFI . CData <EOL> def test_function_with_varargs ( ) : <EOL> import _cffi_backend <EOL> from re_python_pysrc import ffi <EOL> lib = ffi . dlopen ( extmod , <NUM_LIT:0> ) <EOL> assert lib . add43 ( <NUM_LIT> , ffi . cast ( "<STR_LIT:int>" , - <NUM_LIT:5> ) ) == <NUM_LIT> <EOL> assert type ( lib . add43 ) is _cffi_backend . FFI . CData <EOL> def test_dlopen_none ( ) : <EOL> import _cffi_backend <EOL> from re_python_pysrc import ffi <EOL> name = None <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> import ctypes . util <EOL> name = ctypes . util . find_msvcrt ( ) <EOL> lib = ffi . dlopen ( name ) <EOL> assert lib . strlen ( b"<STR_LIT:hello>" ) == <NUM_LIT:5> <EOL> def test_dlclose ( ) : <EOL> import _cffi_backend <EOL> from re_python_pysrc import ffi <EOL> lib = ffi . dlopen ( extmod ) <EOL> ffi . dlclose ( lib ) <EOL> e = py . test . raises ( ffi . error , ffi . dlclose , lib ) <EOL> assert str ( e . value ) . startswith ( <EOL> "<STR_LIT>" % ( extmod , ) ) <EOL> e = py . test . raises ( ffi . error , getattr , lib , '<STR_LIT>' ) <EOL> assert str ( e . value ) == ( <EOL> "<STR_LIT>" % ( extmod , ) ) <EOL> def test_constant_via_lib ( ) : <EOL> from re_python_pysrc import ffi <EOL> lib = ffi . dlopen ( extmod ) <EOL> assert lib . FOOBAR == - <NUM_LIT> <EOL> assert lib . FOOBAZ == - <NUM_LIT> <EOL> def test_opaque_struct ( ) : <EOL> from re_python_pysrc import ffi <EOL> ffi . cast ( "<STR_LIT>" , <NUM_LIT:0> ) <EOL> py . test . raises ( TypeError , ffi . new , "<STR_LIT>" ) <EOL> def test_nonopaque_struct ( ) : <EOL> from re_python_pysrc import ffi <EOL> for p in [ ffi . new ( "<STR_LIT>" , [ <NUM_LIT:5> , b"<STR_LIT>" ] ) , <EOL> ffi . new ( "<STR_LIT>" , [ <NUM_LIT:5> , b"<STR_LIT>" ] ) ] : <EOL> assert p . x == <NUM_LIT:5> <EOL> assert p . a [ <NUM_LIT:0> ] == ord ( '<STR_LIT:f>' ) <EOL> assert p . a [ <NUM_LIT:5> ] == ord ( '<STR_LIT:r>' ) <EOL> def test_enum ( ) : <EOL> from re_python_pysrc import ffi <EOL> assert ffi . integer_const ( "<STR_LIT>" ) == <NUM_LIT:1> <EOL> e = ffi . cast ( "<STR_LIT>" , <NUM_LIT:2> ) <EOL> assert ffi . string ( e ) == "<STR_LIT>" <EOL> def test_include_1 ( ) : <EOL> sub_ffi = FFI ( ) <EOL> sub_ffi . cdef ( "<STR_LIT>" ) <EOL> sub_ffi . include ( original_ffi ) <EOL> assert '<STR_LIT>' in original_ffi . _parser . _declarations <EOL> assert '<STR_LIT>' in original_ffi . _parser . _declarations <EOL> sub_ffi . set_source ( '<STR_LIT>' , None ) <EOL> sub_ffi . emit_python_code ( str ( tmpdir . join ( '<STR_LIT>' ) ) ) <EOL> if sys . version_info [ : <NUM_LIT:2> ] >= ( <NUM_LIT:3> , <NUM_LIT:3> ) : <EOL> import importlib <EOL> importlib . invalidate_caches ( ) <EOL> from _re_include_1 import ffi <EOL> assert ffi . integer_const ( '<STR_LIT>' ) == - <NUM_LIT> <EOL> assert ffi . integer_const ( '<STR_LIT>' ) == - <NUM_LIT> <EOL> assert ffi . integer_const ( '<STR_LIT>' ) == <NUM_LIT> <EOL> lib = ffi . dlopen ( extmod ) <EOL> assert lib . FOOBAR == - <NUM_LIT> <EOL> assert lib . FOOBAZ == - <NUM_LIT> <EOL> assert lib . k2 == <NUM_LIT> <EOL> p = ffi . new ( "<STR_LIT>" , [ <NUM_LIT:5> , b"<STR_LIT>" ] ) <EOL> assert p . a [ <NUM_LIT:4> ] == ord ( '<STR_LIT:a>' ) <EOL> def test_global_var ( ) : <EOL> from re_python_pysrc import ffi <EOL> lib = ffi . dlopen ( extmod ) <EOL> assert lib . globalvar42 == <NUM_LIT> <EOL> p = ffi . addressof ( lib , '<STR_LIT>' ) <EOL> lib . globalvar42 += <NUM_LIT:5> <EOL> assert p [ <NUM_LIT:0> ] == <NUM_LIT> <EOL> p [ <NUM_LIT:0> ] -= <NUM_LIT:1> <EOL> assert lib . globalvar42 == <NUM_LIT> <EOL> def test_global_const_int ( ) : <EOL> from re_python_pysrc import ffi <EOL> lib = ffi . dlopen ( extmod ) <EOL> assert lib . globalconst42 == <NUM_LIT> <EOL> py . test . raises ( AttributeError , ffi . addressof , lib , '<STR_LIT>' ) <EOL> def test_global_const_nonint ( ) : <EOL> from re_python_pysrc import ffi <EOL> lib = ffi . dlopen ( extmod ) <EOL> assert ffi . string ( lib . globalconsthello , <NUM_LIT:8> ) == b"<STR_LIT:hello>" <EOL> py . test . raises ( AttributeError , ffi . addressof , lib , '<STR_LIT>' ) <EOL> def test_rtld_constants ( ) : <EOL> from re_python_pysrc import ffi <EOL> ffi . RTLD_NOW <EOL> ffi . RTLD_LAZY <EOL> ffi . RTLD_GLOBAL <EOL> def test_no_such_function_or_global_var ( ) : <EOL> from re_python_pysrc import ffi <EOL> lib = ffi . dlopen ( extmod ) <EOL> e = py . test . raises ( ffi . error , getattr , lib , '<STR_LIT>' ) <EOL> assert str ( e . value ) . startswith ( <EOL> "<STR_LIT>" ) <EOL> e = py . test . raises ( ffi . error , getattr , lib , '<STR_LIT>' ) <EOL> assert str ( e . value ) . startswith ( <EOL> "<STR_LIT>" ) <EOL> def test_check_version ( ) : <EOL> import _cffi_backend <EOL> e = py . test . raises ( ImportError , _cffi_backend . FFI , <EOL> "<STR_LIT>" , _version = <NUM_LIT> ) <EOL> assert str ( e . value ) . startswith ( <EOL> "<STR_LIT>" ) <EOL> def test_partial_enum ( ) : <EOL> ffi = FFI ( ) <EOL> ffi . cdef ( "<STR_LIT>" ) <EOL> ffi . set_source ( '<STR_LIT>' , None ) <EOL> py . test . raises ( VerificationMissing , ffi . emit_python_code , <EOL> str ( tmpdir . join ( '<STR_LIT>' ) ) ) </s>
