How to use the cffi.CDefError function in cffi

To help you get started, we’ve selected a few cffi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JarryShaw / f2format / vendor / pypy / extra_tests / cffi_tests / cffi1 / test_recompiler.py View on Github external
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;")
github JarryShaw / f2format / vendor / pypy / extra_tests / cffi_tests / cffi0 / test_parsing.py View on Github external
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:')
github opalmer / pywincffi / pywincffi / dev / testutil.py View on Github external
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(
github mozillazg / pypy / extra_tests / cffi_tests / cffi1 / test_recompiler.py View on Github external
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;")
github JarryShaw / f2format / vendor / pypy / extra_tests / cffi_tests / cffi0 / test_parsing.py View on Github external
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'
github holzschu / python3_ios / extraPackages / cffi-1.11.5 / testing / cffi0 / test_parsing.py View on Github external
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)"')
github holzschu / python3_ios / extraPackages / cffi-1.11.5 / testing / cffi0 / test_parsing.py View on Github external
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'
github mozillazg / pypy / extra_tests / cffi_tests / cffi1 / test_dlopen.py View on Github external
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:")
github cloudera / hue / desktop / core / ext-py / cffi-1.11.5 / demo / api.py View on Github external
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
github holzschu / python3_ios / extraPackages / cffi-1.11.5 / demo / api.py View on Github external
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