Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_enum():
ffi = FFI()
ffi.cdef("enum myenum_e { AA, BB, CC=-42 };")
target = udir.join('test_enum.py')
make_py_source(ffi, 'test_enum', str(target))
assert target.read() == r"""# auto-generated file
import _cffi_backend
def test_struct():
ffi = FFI()
ffi.cdef("struct foo_s { int a; signed char b[]; }; struct bar_s;")
target = udir.join('test_struct.py')
make_py_source(ffi, 'test_struct', str(target))
assert target.read() == r"""# auto-generated file
import _cffi_backend
def test_simple():
ffi = FFI()
ffi.cdef("int close(int); static const int BB = 42; extern int somevar;")
target = udir.join('test_simple.py')
make_py_source(ffi, 'test_simple', str(target))
assert target.read() == r"""# auto-generated file
import _cffi_backend
def test_include():
ffi = FFI()
ffi.cdef("#define ABC 123")
ffi.set_source('test_include', None)
target = udir.join('test_include.py')
make_py_source(ffi, 'test_include', str(target))
assert target.read() == r"""# auto-generated file
import _cffi_backend
ffi = _cffi_backend.FFI('test_include',
_version = 0x2601,
_types = b'',
_globals = (b'\xFF\xFF\xFF\x1FABC',123,),
)
"""
#
ffi2 = FFI()
ffi2.include(ffi)
target2 = udir.join('test2_include.py')
make_py_source(ffi2, 'test2_include', str(target2))
assert target2.read() == r"""# auto-generated file
import _cffi_backend
def test_negative_constant():
ffi = FFI()
ffi.cdef("static const int BB = -42;")
target = udir.join('test_negative_constant.py')
make_py_source(ffi, 'test_negative_constant', str(target))
assert target.read() == r"""# auto-generated file
import _cffi_backend
def test_simple():
ffi = FFI()
ffi.cdef("int close(int); static const int BB = 42; int somevar;")
target = udir.join('test_simple.py')
make_py_source(ffi, 'test_simple', str(target))
assert target.read() == r"""# auto-generated file
import _cffi_backend
def test_bitfield():
ffi = FFI()
ffi.cdef("struct foo_s { int y:10; short x:5; };")
target = udir.join('test_bitfield.py')
make_py_source(ffi, 'test_bitfield', str(target))
assert target.read() == r"""# auto-generated file
import _cffi_backend
def test_global_constant():
ffi = FFI()
ffi.cdef("static const long BB; static const float BF = 12;")
target = udir.join('test_valid_global_constant.py')
make_py_source(ffi, 'test_valid_global_constant', str(target))
assert target.read() == r"""# auto-generated file
import _cffi_backend
def generate_mod(py_file):
log.info("generating cffi module %r" % py_file)
mkpath(os.path.dirname(py_file))
updated = recompiler.make_py_source(ffi, module_name, py_file)
if not updated:
log.info("already up-to-date")
def generate_mod(py_file):
log.info("generating cffi module %r" % py_file)
mkpath(os.path.dirname(py_file))
updated = recompiler.make_py_source(ffi, module_name, py_file)
if not updated:
log.info("already up-to-date")