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_some_float_invalid_1():
ffi = FFI()
py.test.raises((FFIError, # with pycparser <= 2.17
CDefError), # with pycparser >= 2.18
ffi.cdef, "typedef long double... foo_t;")
def test_parse_error():
ffi = FFI()
e = py.test.raises(CDefError, ffi.cdef, " x y z ")
assert str(e.value).startswith(
'cannot parse "x y z"\n:1:')
e = py.test.raises(CDefError, ffi.cdef, "\n\n\n x y z ")
assert str(e.value).startswith(
'cannot parse "x y z"\n:4:')
except NameError: # pragma: no cover
WindowsError = OSError # pylint: disable=redefined-builtin
# Load in our own kernel32 with the function(s) we need
# so we don't have to rely on pywincffi.core
libtest = None # pylint: disable=invalid-name
ffi = FFI()
# pylint: disable=invalid-name
skip_unless_python2 = skipUnless(PY2, "Not Python 2")
skip_unless_python3 = skipUnless(PY3, "Not Python 3")
try:
ffi.cdef("void SetLastError(DWORD);")
libtest = ffi.dlopen("kernel32") # pylint: disable=invalid-name
except (AttributeError, OSError, CDefError): # pragma: no cover
if os.name == "nt":
logger.warning("Failed to build SetLastError()")
class TestCase(_TestCase):
"""
A base class for all test cases. By default the
core test case just provides some extra functionality.
"""
REQUIRES_INTERNET = False
_HAS_INTERNET = None
def setUp(self): # pragma: no cover
if self.REQUIRES_INTERNET and not self.internet_connected():
if os.environ.get("CI"):
self.fail(
def test_some_float_invalid_1():
ffi = FFI()
py.test.raises((FFIError, # with pycparser <= 2.17
CDefError), # with pycparser >= 2.18
ffi.cdef, "typedef long double... foo_t;")
def test_define_not_supported_for_now():
ffi = FFI(backend=FakeBackend())
e = py.test.raises(CDefError, ffi.cdef, '#define FOO "blah"')
assert str(e.value) == (
'only supports one of the following syntax:\n'
' #define FOO ... (literally dot-dot-dot)\n'
def test_unknown_name():
ffi = FFI()
e = py.test.raises(CDefError, ffi.cast, "foobarbazunknown", 0)
assert str(e.value) == "unknown identifier 'foobarbazunknown'"
e = py.test.raises(CDefError, ffi.cast, "foobarbazunknown*", 0)
assert str(e.value).startswith('cannot parse "foobarbazunknown*"')
e = py.test.raises(CDefError, ffi.cast, "int(*)(foobarbazunknown)", 0)
assert str(e.value).startswith('cannot parse "int(*)(foobarbazunknown)"')
def test_define_not_supported_for_now():
ffi = FFI(backend=FakeBackend())
e = py.test.raises(CDefError, ffi.cdef, '#define FOO "blah"')
assert str(e.value) == (
'only supports one of the following syntax:\n'
' #define FOO ... (literally dot-dot-dot)\n'
def test_invalid_global_constant_3():
ffi = FFI()
e = py.test.raises(CDefError, ffi.cdef, "#define BB 12.34")
assert str(e.value).startswith(
"only supports one of the following syntax:")
def decorator(func):
name = func.__name__
if name in self._pyexports:
raise cffi.CDefError("duplicate pyexport'ed function %r"
% (name,))
callback_var = self.getctype(tp, name)
self.cdef("%s;" % callback_var)
self._pyexports[name] = _PyExport(tp, func)
return decorator
def decorator(func):
name = func.__name__
if name in self._pyexports:
raise cffi.CDefError("duplicate pyexport'ed function %r"
% (name,))
callback_var = self.getctype(tp, name)
self.cdef("%s;" % callback_var)
self._pyexports[name] = _PyExport(tp, func)
return decorator