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_cffi_opcode_sync():
import cffi.model
for name in dir(lib):
if name.startswith('_CFFI_'):
assert getattr(cffi_opcode, name[6:]) == getattr(lib, name)
assert sorted(cffi_opcode.PRIMITIVE_TO_INDEX.keys()) == (
sorted(cffi.model.PrimitiveType.ALL_PRIMITIVE_TYPES.keys()))
def test_primitive_category():
for typename in all_primitive_types:
tp = model.PrimitiveType(typename)
C = tp.is_char_type()
F = tp.is_float_type()
X = tp.is_complex_type()
I = tp.is_integer_type()
assert C == (typename in ('char', 'wchar_t', 'char16_t', 'char32_t'))
assert F == (typename in ('float', 'double', 'long double'))
assert X == (typename in ('float _Complex', 'double _Complex'))
assert I + F + C + X == 1 # one and only one of them is true
def test_primitive_category():
for typename in all_primitive_types:
tp = model.PrimitiveType(typename)
C = tp.is_char_type()
F = tp.is_float_type()
X = tp.is_complex_type()
I = tp.is_integer_type()
assert C == (typename in ('char', 'wchar_t', 'char16_t', 'char32_t'))
assert F == (typename in ('float', 'double', 'long double'))
assert X == (typename in ('float _Complex', 'double _Complex'))
assert I + F + C + X == 1 # one and only one of them is true
else:
assert abs(more_precise - less_precise) > 0.1
# Check the particular results on Intel
import platform
if (platform.machine().startswith('i386') or
platform.machine().startswith('i486') or
platform.machine().startswith('i586') or
platform.machine().startswith('i686') or
platform.machine().startswith('x86')):
assert abs(more_precise - 0.656769) < 0.001
assert abs(less_precise - 3.99091) < 0.001
else:
py.test.skip("don't know the very exact precision of 'long double'")
all_primitive_types = model.PrimitiveType.ALL_PRIMITIVE_TYPES
if sys.platform == 'win32':
all_primitive_types = all_primitive_types.copy()
del all_primitive_types['ssize_t']
all_integer_types = sorted(tp for tp in all_primitive_types
if all_primitive_types[tp] == 'i')
all_float_types = sorted(tp for tp in all_primitive_types
if all_primitive_types[tp] == 'f')
def all_signed_integer_types(ffi):
return [x for x in all_integer_types if int(ffi.cast(x, -1)) < 0]
def all_unsigned_integer_types(ffi):
return [x for x in all_integer_types if int(ffi.cast(x, -1)) > 0]
def test_primitive_category():