summaryrefslogtreecommitdiff
path: root/testing/cffi0
diff options
context:
space:
mode:
Diffstat (limited to 'testing/cffi0')
-rw-r--r--testing/cffi0/backend_tests.py151
-rw-r--r--testing/cffi0/test_cdata.py1
-rw-r--r--testing/cffi0/test_ctypes.py21
-rw-r--r--testing/cffi0/test_ffi_backend.py40
-rw-r--r--testing/cffi0/test_function.py57
-rw-r--r--testing/cffi0/test_ownlib.py51
-rw-r--r--testing/cffi0/test_parsing.py47
-rw-r--r--testing/cffi0/test_verify.py190
-rw-r--r--testing/cffi0/test_version.py5
-rw-r--r--testing/cffi0/test_zdistutils.py4
-rw-r--r--testing/cffi0/test_zintegration.py4
11 files changed, 286 insertions, 285 deletions
diff --git a/testing/cffi0/backend_tests.py b/testing/cffi0/backend_tests.py
index ab013a1..aed1b9c 100644
--- a/testing/cffi0/backend_tests.py
+++ b/testing/cffi0/backend_tests.py
@@ -1,4 +1,3 @@
-import py
import pytest
import platform
import sys, ctypes, ctypes.util
@@ -13,7 +12,7 @@ SIZE_OF_WCHAR = ctypes.sizeof(ctypes.c_wchar)
def needs_dlopen_none():
if sys.platform == 'win32' and not ctypes.util.find_library('c'):
- py.test.skip("dlopen(None) cannot work on Windows with this runtime")
+ pytest.skip("dlopen(None) cannot work on Windows with this runtime")
class BackendTests:
@@ -75,10 +74,10 @@ class BackendTests:
assert int(q) == int(p)
assert hash(q) == hash(p)
c_decl_ptr = '%s *' % c_decl
- py.test.raises(OverflowError, ffi.new, c_decl_ptr, min - 1)
- py.test.raises(OverflowError, ffi.new, c_decl_ptr, max + 1)
- py.test.raises(OverflowError, ffi.new, c_decl_ptr, long(min - 1))
- py.test.raises(OverflowError, ffi.new, c_decl_ptr, long(max + 1))
+ pytest.raises(OverflowError, ffi.new, c_decl_ptr, min - 1)
+ pytest.raises(OverflowError, ffi.new, c_decl_ptr, max + 1)
+ pytest.raises(OverflowError, ffi.new, c_decl_ptr, long(min - 1))
+ pytest.raises(OverflowError, ffi.new, c_decl_ptr, long(max + 1))
assert ffi.new(c_decl_ptr, min)[0] == min
assert ffi.new(c_decl_ptr, max)[0] == max
assert ffi.new(c_decl_ptr, long(min))[0] == min
@@ -86,7 +85,7 @@ class BackendTests:
def test_new_unsupported_type(self):
ffi = FFI(backend=self.Backend())
- e = py.test.raises(TypeError, ffi.new, "int")
+ e = pytest.raises(TypeError, ffi.new, "int")
assert str(e.value) == "expected a pointer or array ctype, got 'int'"
def test_new_single_integer(self):
@@ -148,7 +147,7 @@ class BackendTests:
with pytest.raises(IndexError):
p[10]
#
- py.test.raises(TypeError, ffi.new, "int[]")
+ pytest.raises(TypeError, ffi.new, "int[]")
#
p = ffi.new("int[]", [-6, -7]) # a list is all the items, like C
assert p[0] == -6
@@ -160,7 +159,7 @@ class BackendTests:
p = ffi.new("int[]", 0)
with pytest.raises(IndexError):
p[0]
- py.test.raises(ValueError, ffi.new, "int[]", -1)
+ pytest.raises(ValueError, ffi.new, "int[]", -1)
assert repr(p) == "<cdata 'int[]' owning 0 bytes>"
def test_pointer_init(self):
@@ -175,7 +174,7 @@ class BackendTests:
def test_cannot_cast(self):
ffi = FFI(backend=self.Backend())
a = ffi.new("short int[10]")
- e = py.test.raises(TypeError, ffi.new, "long int **", a)
+ e = pytest.raises(TypeError, ffi.new, "long int **", a)
msg = str(e.value)
assert "'short[10]'" in msg and "'long *'" in msg
@@ -301,9 +300,9 @@ class BackendTests:
assert not bool(ffi.cast("char", 0))
assert bool(ffi.cast("char", 1))
assert bool(ffi.cast("char", 255))
- py.test.raises(TypeError, ffi.new, "char*", 32)
- py.test.raises(TypeError, ffi.new, "char*", u+"x")
- py.test.raises(TypeError, ffi.new, "char*", b"foo")
+ pytest.raises(TypeError, ffi.new, "char*", 32)
+ pytest.raises(TypeError, ffi.new, "char*", u+"x")
+ pytest.raises(TypeError, ffi.new, "char*", b"foo")
#
p = ffi.new("char[]", [b'a', b'b', b'\x9c'])
assert len(p) == 3
@@ -322,13 +321,13 @@ class BackendTests:
p = ffi.new("char[2]", b"ab")
assert len(p) == 2
assert [p[i] for i in range(2)] == [b'a', b'b']
- py.test.raises(IndexError, ffi.new, "char[2]", b"abc")
+ pytest.raises(IndexError, ffi.new, "char[2]", b"abc")
def check_wchar_t(self, ffi):
try:
ffi.cast("wchar_t", 0)
except NotImplementedError:
- py.test.skip("NotImplementedError: wchar_t")
+ pytest.skip("NotImplementedError: wchar_t")
def test_wchar_t(self):
ffi = FFI(backend=self.Backend())
@@ -338,7 +337,7 @@ class BackendTests:
if SIZE_OF_WCHAR > 2:
assert ffi.new("wchar_t*", u+'\U00012345')[0] == u+'\U00012345'
else:
- py.test.raises(TypeError, ffi.new, "wchar_t*", u+'\U00012345')
+ pytest.raises(TypeError, ffi.new, "wchar_t*", u+'\U00012345')
assert ffi.new("wchar_t*")[0] == u+'\x00'
assert int(ffi.cast("wchar_t", 300)) == 300
assert not bool(ffi.cast("wchar_t", 0))
@@ -346,8 +345,8 @@ class BackendTests:
assert bool(ffi.cast("wchar_t", 65535))
if SIZE_OF_WCHAR > 2:
assert bool(ffi.cast("wchar_t", 65536))
- py.test.raises(TypeError, ffi.new, "wchar_t*", 32)
- py.test.raises(TypeError, ffi.new, "wchar_t*", "foo")
+ pytest.raises(TypeError, ffi.new, "wchar_t*", 32)
+ pytest.raises(TypeError, ffi.new, "wchar_t*", "foo")
#
p = ffi.new("wchar_t[]", [u+'a', u+'b', u+'\u1234'])
assert len(p) == 3
@@ -382,7 +381,7 @@ class BackendTests:
p = ffi.new("wchar_t[2]", u+"ab")
assert len(p) == 2
assert [p[i] for i in range(2)] == [u+'a', u+'b']
- py.test.raises(IndexError, ffi.new, "wchar_t[2]", u+"abc")
+ pytest.raises(IndexError, ffi.new, "wchar_t[2]", u+"abc")
def test_none_as_null_doesnt_work(self):
ffi = FFI(backend=self.Backend())
@@ -410,8 +409,8 @@ class BackendTests:
#
p = ffi.new("float*", 15.75)
assert p[0] == 15.75
- py.test.raises(TypeError, int, p)
- py.test.raises(TypeError, float, p)
+ pytest.raises(TypeError, int, p)
+ pytest.raises(TypeError, float, p)
p[0] = 0.0
assert bool(p) is True
#
@@ -444,7 +443,7 @@ class BackendTests:
assert repr(s) == "<cdata 'struct foo *' owning %d bytes>" % (
SIZE_OF_INT + 2 * SIZE_OF_SHORT)
#
- py.test.raises(ValueError, ffi.new, "struct foo*", [1, 2, 3, 4])
+ pytest.raises(ValueError, ffi.new, "struct foo*", [1, 2, 3, 4])
def test_constructor_struct_from_dict(self):
ffi = FFI(backend=self.Backend())
@@ -453,7 +452,7 @@ class BackendTests:
assert s.a == 0
assert s.b == 123
assert s.c == 456
- py.test.raises(KeyError, ffi.new, "struct foo*", {'d': 456})
+ pytest.raises(KeyError, ffi.new, "struct foo*", {'d': 456})
def test_struct_pointer(self):
ffi = FFI(backend=self.Backend())
@@ -469,7 +468,7 @@ class BackendTests:
def test_struct_opaque(self):
ffi = FFI(backend=self.Backend())
- py.test.raises(TypeError, ffi.new, "struct baz*")
+ pytest.raises(TypeError, ffi.new, "struct baz*")
p = ffi.new("struct baz **") # this works
assert p[0] == ffi.NULL
@@ -536,19 +535,19 @@ class BackendTests:
def test_union_opaque(self):
ffi = FFI(backend=self.Backend())
- py.test.raises(TypeError, ffi.new, "union baz *")
+ pytest.raises(TypeError, ffi.new, "union baz *")
u = ffi.new("union baz **") # this works
assert u[0] == ffi.NULL
def test_union_initializer(self):
ffi = FFI(backend=self.Backend())
ffi.cdef("union foo { char a; int b; };")
- py.test.raises(TypeError, ffi.new, "union foo*", b'A')
- py.test.raises(TypeError, ffi.new, "union foo*", 5)
- py.test.raises(ValueError, ffi.new, "union foo*", [b'A', 5])
+ pytest.raises(TypeError, ffi.new, "union foo*", b'A')
+ pytest.raises(TypeError, ffi.new, "union foo*", 5)
+ pytest.raises(ValueError, ffi.new, "union foo*", [b'A', 5])
u = ffi.new("union foo*", [b'A'])
assert u.a == b'A'
- py.test.raises(TypeError, ffi.new, "union foo*", [1005])
+ pytest.raises(TypeError, ffi.new, "union foo*", [1005])
u = ffi.new("union foo*", {'b': 12345})
assert u.b == 12345
u = ffi.new("union foo*", [])
@@ -587,7 +586,7 @@ class BackendTests:
assert str(x) == repr(x)
assert ffi.string(x) == b"x"
assert ffi.string(ffi.new("char*", b"\x00")) == b""
- py.test.raises(TypeError, ffi.new, "char*", unicode("foo"))
+ pytest.raises(TypeError, ffi.new, "char*", unicode("foo"))
def test_unicode_from_wchar_pointer(self):
ffi = FFI(backend=self.Backend())
@@ -670,7 +669,7 @@ class BackendTests:
def test_voidp(self):
ffi = FFI(backend=self.Backend())
- py.test.raises(TypeError, ffi.new, "void*")
+ pytest.raises(TypeError, ffi.new, "void*")
p = ffi.new("void **")
assert p[0] == ffi.NULL
a = ffi.new("int[]", [10, 11, 12])
@@ -678,7 +677,7 @@ class BackendTests:
vp = p[0]
with pytest.raises(TypeError):
vp[0]
- py.test.raises(TypeError, ffi.new, "short **", a)
+ pytest.raises(TypeError, ffi.new, "short **", a)
#
ffi.cdef("struct foo { void *p; int *q; short *r; };")
s = ffi.new("struct foo *")
@@ -694,7 +693,7 @@ class BackendTests:
def test_functionptr_simple(self):
ffi = FFI(backend=self.Backend())
- py.test.raises(TypeError, ffi.callback, "int(*)(int)", 0)
+ pytest.raises(TypeError, ffi.callback, "int(*)(int)", 0)
def cb(n):
return n + 1
cb.__qualname__ = 'cb'
@@ -970,7 +969,7 @@ class BackendTests:
needs_dlopen_none()
lib = ffi.dlopen(None)
assert lib.B == 0
- py.test.raises(VerificationMissing, getattr, lib, "A")
+ pytest.raises(VerificationMissing, getattr, lib, "A")
assert lib.C == 1
def test_array_of_struct(self):
@@ -997,10 +996,10 @@ class BackendTests:
assert list(a) == [b"h", b"e", b"l", b"l", b"o", b"\0"]
assert list(iter(a)) == [b"h", b"e", b"l", b"l", b"o", b"\0"]
#
- py.test.raises(TypeError, iter, ffi.cast("char *", a))
- py.test.raises(TypeError, list, ffi.cast("char *", a))
- py.test.raises(TypeError, iter, ffi.new("int *"))
- py.test.raises(TypeError, list, ffi.new("int *"))
+ pytest.raises(TypeError, iter, ffi.cast("char *", a))
+ pytest.raises(TypeError, list, ffi.cast("char *", a))
+ pytest.raises(TypeError, iter, ffi.new("int *"))
+ pytest.raises(TypeError, list, ffi.new("int *"))
def test_offsetof(self):
ffi = FFI(backend=self.Backend())
@@ -1014,7 +1013,7 @@ class BackendTests:
ffi.cdef("struct foo { int a, b, c; };"
"struct bar { struct foo d, e; };")
assert ffi.offsetof("struct bar", "e") == 12
- py.test.raises(KeyError, ffi.offsetof, "struct bar", "e.a")
+ pytest.raises(KeyError, ffi.offsetof, "struct bar", "e.a")
assert ffi.offsetof("struct bar", "e", "a") == 12
assert ffi.offsetof("struct bar", "e", "b") == 16
assert ffi.offsetof("struct bar", "e", "c") == 20
@@ -1170,7 +1169,7 @@ class BackendTests:
try:
b = ffi.buffer(a)
except NotImplementedError as e:
- py.test.skip(str(e))
+ pytest.skip(str(e))
assert type(b) is ffi.buffer
content = b[:]
assert len(content) == len(b) == 2
@@ -1190,7 +1189,7 @@ class BackendTests:
try:
b = ffi.buffer(a)
except NotImplementedError as e:
- py.test.skip(str(e))
+ pytest.skip(str(e))
content = b[:]
if sys.byteorder == 'little':
assert content.startswith(b'\x64\x00\x00\x00\x65\x00\x00\x00')
@@ -1207,7 +1206,7 @@ class BackendTests:
try:
b = ffi.buffer(a, 1)
except NotImplementedError as e:
- py.test.skip(str(e))
+ pytest.skip(str(e))
content = b[:]
assert len(content) == 1
if sys.byteorder == 'little':
@@ -1226,7 +1225,7 @@ class BackendTests:
try:
ffi.buffer(a1)
except NotImplementedError as e:
- py.test.skip(str(e))
+ pytest.skip(str(e))
assert ffi.buffer(a1)[:] == ffi.buffer(a2, 4*10)[:]
def test_ffi_buffer_with_file(self):
@@ -1238,7 +1237,7 @@ class BackendTests:
try:
ffi.buffer(a, 512)
except NotImplementedError as e:
- py.test.skip(str(e))
+ pytest.skip(str(e))
f.write(ffi.buffer(a, 1000 * ffi.sizeof("int")))
f.seek(0)
assert f.read() == arraytostring(array.array('i', range(1000)))
@@ -1257,7 +1256,7 @@ class BackendTests:
try:
ffi.buffer(a, 512)
except NotImplementedError as e:
- py.test.skip(str(e))
+ pytest.skip(str(e))
f.write(ffi.buffer(a, 1000 * ffi.sizeof("int")))
f.seek(0)
assert f.read() == arraytostring(array.array('i', range(1000)))
@@ -1280,7 +1279,7 @@ class BackendTests:
b_mid = ffi.buffer(a, 6)
b_other = ffi.buffer(c, 6)
except NotImplementedError as e:
- py.test.skip(str(e))
+ pytest.skip(str(e))
else:
content = b_full[:]
assert content == b_full == ba
@@ -1309,7 +1308,7 @@ class BackendTests:
assert q.data[6] == 15
def test_new_struct_containing_array_varsize(self):
- py.test.skip("later?")
+ pytest.skip("later?")
ffi = FFI(backend=self.Backend())
ffi.cdef("struct foo_s { int len; short data[]; };")
p = ffi.new("struct foo_s *", 10) # a single integer is the length
@@ -1340,14 +1339,14 @@ class BackendTests:
ffi = FFI(backend=self.Backend())
f = ffi.cast("int(*)(int)", 42)
assert f != ffi.NULL
- py.test.raises(CDefError, ffi.cast, "int(int)", 42)
- py.test.raises(CDefError, ffi.new, "int([5])(int)")
+ pytest.raises(CDefError, ffi.cast, "int(int)", 42)
+ pytest.raises(CDefError, ffi.new, "int([5])(int)")
a = ffi.new("int(*[5])(int)", [f])
assert ffi.getctype(ffi.typeof(a)) == "int(*[5])(int)"
assert len(a) == 5
assert a[0] == f
assert a[1] == ffi.NULL
- py.test.raises(TypeError, ffi.cast, "int(*)(int)[5]", 0)
+ pytest.raises(TypeError, ffi.cast, "int(*)(int)[5]", 0)
#
def cb(n):
return n + 1
@@ -1369,7 +1368,7 @@ class BackendTests:
assert g(f) == b'B'
def test_vararg_callback(self):
- py.test.skip("callback with '...'")
+ pytest.skip("callback with '...'")
ffi = FFI(backend=self.Backend())
def cb(i, va_list):
j = ffi.va_arg(va_list, "int")
@@ -1433,7 +1432,7 @@ class BackendTests:
def test_new_ctype(self):
ffi = FFI(backend=self.Backend())
p = ffi.new("int *")
- py.test.raises(TypeError, ffi.new, p)
+ pytest.raises(TypeError, ffi.new, p)
p = ffi.new(ffi.typeof("int *"), 42)
assert p[0] == 42
@@ -1479,7 +1478,7 @@ class BackendTests:
assert p.b == 12
assert p.c == 14
assert p.d == 14
- py.test.raises(ValueError, ffi.new, "struct foo_s *", [0, 0, 0, 0])
+ pytest.raises(ValueError, ffi.new, "struct foo_s *", [0, 0, 0, 0])
def test_nested_field_offset_align(self):
ffi = FFI(backend=self.Backend())
@@ -1529,7 +1528,7 @@ class BackendTests:
assert p.b == 456
assert p.c == 123
assert p.d == 123
- py.test.raises(ValueError, ffi.new, "union foo_u *", [0, 0, 0])
+ pytest.raises(ValueError, ffi.new, "union foo_u *", [0, 0, 0])
def test_nested_anonymous_struct_2(self):
ffi = FFI(backend=self.Backend())
@@ -1545,7 +1544,7 @@ class BackendTests:
assert p.a == 11
assert p.b == p.c == p.d == 22
assert p.e == 33
- py.test.raises(ValueError, ffi.new, "struct foo_s *", [11, 22, 33, 44])
+ pytest.raises(ValueError, ffi.new, "struct foo_s *", [11, 22, 33, 44])
FOO = ffi.typeof("struct foo_s")
fields = [(name, fld.offset, fld.flags) for (name, fld) in FOO.fields]
assert fields == [
@@ -1626,7 +1625,7 @@ class BackendTests:
def test_gc_disable(self):
ffi = FFI(backend=self.Backend())
p = ffi.new("int *", 123)
- py.test.raises(TypeError, ffi.gc, p, None)
+ pytest.raises(TypeError, ffi.gc, p, None)
seen = []
q1 = ffi.gc(p, lambda p: seen.append(1))
q2 = ffi.gc(q1, lambda p: seen.append(2))
@@ -1669,8 +1668,8 @@ class BackendTests:
assert int(ffi.cast("_Bool", b'\x80')) == 1
assert ffi.new("_Bool *", False)[0] == 0
assert ffi.new("_Bool *", 1)[0] == 1
- py.test.raises(OverflowError, ffi.new, "_Bool *", 2)
- py.test.raises(TypeError, ffi.string, ffi.cast("_Bool", 2))
+ pytest.raises(OverflowError, ffi.new, "_Bool *", 2)
+ pytest.raises(TypeError, ffi.string, ffi.cast("_Bool", 2))
def test_use_own_bool(self):
ffi = FFI(backend=self.Backend())
@@ -1713,9 +1712,9 @@ class BackendTests:
a = ffi.addressof(p[0])
assert repr(a).startswith("<cdata 'struct foo_s *' 0x")
assert a == p
- py.test.raises(TypeError, ffi.addressof, p)
- py.test.raises((AttributeError, TypeError), ffi.addressof, 5)
- py.test.raises(TypeError, ffi.addressof, ffi.cast("int", 5))
+ pytest.raises(TypeError, ffi.addressof, p)
+ pytest.raises((AttributeError, TypeError), ffi.addressof, 5)
+ pytest.raises(TypeError, ffi.addressof, ffi.cast("int", 5))
def test_addressof_field(self):
ffi = FFI(backend=self.Backend())
@@ -1733,7 +1732,7 @@ class BackendTests:
ffi.cdef("struct foo_s { int x, y; };"
"struct bar_s { struct foo_s a, b; };")
p = ffi.new("struct bar_s *")
- py.test.raises(KeyError, ffi.addressof, p[0], 'b.y')
+ pytest.raises(KeyError, ffi.addressof, p[0], 'b.y')
a = ffi.addressof(p[0], 'b', 'y')
assert int(ffi.cast("uintptr_t", a)) == (
int(ffi.cast("uintptr_t", p)) +
@@ -1752,7 +1751,7 @@ class BackendTests:
p0 = ffi.addressof(p)
assert p0 == p
assert ffi.typeof(p0) is ffi.typeof("int(*)[52]")
- py.test.raises(TypeError, ffi.addressof, p0)
+ pytest.raises(TypeError, ffi.addressof, p0)
#
p1 = ffi.addressof(p, 25)
assert ffi.typeof(p1) is ffi.typeof("int *")
@@ -1763,7 +1762,7 @@ class BackendTests:
ffi = FFI()
array = ffi.new("int[50]")
p = ffi.cast("int *", array)
- py.test.raises(TypeError, ffi.addressof, p)
+ pytest.raises(TypeError, ffi.addressof, p)
assert ffi.addressof(p, 0) == p
assert ffi.addressof(p, 25) == p + 25
assert ffi.typeof(ffi.addressof(p, 25)) == ffi.typeof(p)
@@ -1771,7 +1770,7 @@ class BackendTests:
ffi.cdef("struct foo { int a, b; };")
array = ffi.new("struct foo[50]")
p = ffi.cast("int *", array)
- py.test.raises(TypeError, ffi.addressof, p)
+ pytest.raises(TypeError, ffi.addressof, p)
assert ffi.addressof(p, 0) == p
assert ffi.addressof(p, 25) == p + 25
assert ffi.typeof(ffi.addressof(p, 25)) == ffi.typeof(p)
@@ -1803,7 +1802,7 @@ class BackendTests:
ffi1 = FFI(backend=backend)
ffi2 = FFI(backend=backend)
ffi1.cdef("typedef signed char schar_t;")
- py.test.raises(CDefError, ffi2.cast, "schar_t", 142)
+ pytest.raises(CDefError, ffi2.cast, "schar_t", 142)
def test_include_typedef(self):
backend = self.Backend()
@@ -1855,7 +1854,7 @@ class BackendTests:
ffi = FFI(backend=self.Backend())
ffi.cdef("#define FOO 42")
ffi.cdef("#define FOO 42")
- py.test.raises(FFIError, ffi.cdef, "#define FOO 43")
+ pytest.raises(FFIError, ffi.cdef, "#define FOO 43")
def test_struct_packed(self):
ffi = FFI(backend=self.Backend())
@@ -1891,9 +1890,9 @@ class BackendTests:
def test_pack_valueerror(self):
ffi = FFI(backend=self.Backend())
- py.test.raises(ValueError, ffi.cdef, "", pack=3)
- py.test.raises(ValueError, ffi.cdef, "", packed=2)
- py.test.raises(ValueError, ffi.cdef, "", packed=True, pack=1)
+ pytest.raises(ValueError, ffi.cdef, "", pack=3)
+ pytest.raises(ValueError, ffi.cdef, "", packed=2)
+ pytest.raises(ValueError, ffi.cdef, "", packed=True, pack=1)
def test_define_integer_constant(self):
ffi = FFI(backend=self.Backend())
@@ -1922,13 +1921,13 @@ class BackendTests:
# definition was ignored.
ffi = FFI(backend=self.Backend())
ffi.cdef("struct foo_s;")
- py.test.raises(TypeError, ffi.new, "struct foo_s *")
+ pytest.raises(TypeError, ffi.new, "struct foo_s *")
ffi.cdef("struct foo_s { int x; };")
ffi.new("struct foo_s *")
def test_ffi_self_include(self):
ffi = FFI(backend=self.Backend())
- py.test.raises(ValueError, ffi.include, ffi)
+ pytest.raises(ValueError, ffi.include, ffi)
def test_anonymous_enum_include(self):
ffi1 = FFI()
@@ -2016,12 +2015,12 @@ class BackendTests:
p = ffi.new("int[4]", [10, 20, 30, 400])
q = ffi.new("int[4]", p)
assert list(q) == [10, 20, 30, 400]
- py.test.raises(TypeError, ffi.new, "int[3]", p)
- py.test.raises(TypeError, ffi.new, "int[5]", p)
- py.test.raises(TypeError, ffi.new, "int16_t[4]", p)
+ pytest.raises(TypeError, ffi.new, "int[3]", p)
+ pytest.raises(TypeError, ffi.new, "int[5]", p)
+ pytest.raises(TypeError, ffi.new, "int16_t[4]", p)
s = ffi.new("struct {int i[4];}*", {'i': p})
assert list(s.i) == [10, 20, 30, 400]
def test_too_many_initializers(self):
ffi = FFI(backend=self.Backend())
- py.test.raises(IndexError, ffi.new, "int[4]", [10, 20, 30, 40, 50])
+ pytest.raises(IndexError, ffi.new, "int[4]", [10, 20, 30, 40, 50])
diff --git a/testing/cffi0/test_cdata.py b/testing/cffi0/test_cdata.py
index 23989ab..b044c0a 100644
--- a/testing/cffi0/test_cdata.py
+++ b/testing/cffi0/test_cdata.py
@@ -1,4 +1,3 @@
-import py
from cffi import FFI
class FakeBackend(object):
diff --git a/testing/cffi0/test_ctypes.py b/testing/cffi0/test_ctypes.py
index a70c8f0..2a3b84f 100644
--- a/testing/cffi0/test_ctypes.py
+++ b/testing/cffi0/test_ctypes.py
@@ -1,4 +1,5 @@
-import py, sys
+import sys
+import pytest
from testing.cffi0 import backend_tests
from cffi.backend_ctypes import CTypesBackend
@@ -11,33 +12,33 @@ class TestCTypes(backend_tests.BackendTests):
TypeRepr = "<class 'ffi.CData<%s>'>"
def test_array_of_func_ptr(self):
- py.test.skip("ctypes backend: not supported: "
+ pytest.skip("ctypes backend: not supported: "
"initializers for function pointers")
def test_structptr_argument(self):
- py.test.skip("ctypes backend: not supported: passing a list "
+ pytest.skip("ctypes backend: not supported: passing a list "
"for a pointer argument")
def test_array_argument_as_list(self):
- py.test.skip("ctypes backend: not supported: passing a list "
+ pytest.skip("ctypes backend: not supported: passing a list "
"for a pointer argument")
def test_cast_to_array_type(self):
- py.test.skip("ctypes backend: not supported: casting to array")
+ pytest.skip("ctypes backend: not supported: casting to array")
def test_nested_anonymous_struct(self):
- py.test.skip("ctypes backend: not supported: nested anonymous struct")
+ pytest.skip("ctypes backend: not supported: nested anonymous struct")
def test_nested_field_offset_align(self):
- py.test.skip("ctypes backend: not supported: nested anonymous struct")
+ pytest.skip("ctypes backend: not supported: nested anonymous struct")
def test_nested_anonymous_union(self):
- py.test.skip("ctypes backend: not supported: nested anonymous union")
+ pytest.skip("ctypes backend: not supported: nested anonymous union")
def test_nested_anonymous_struct_2(self):
- py.test.skip("ctypes backend: not supported: nested anonymous union")
+ pytest.skip("ctypes backend: not supported: nested anonymous union")
def test_CData_CType_2(self):
if sys.version_info >= (3,):
- py.test.skip("ctypes backend: not supported in Python 3: CType")
+ pytest.skip("ctypes backend: not supported in Python 3: CType")
backend_tests.BackendTests.test_CData_CType_2(self)
diff --git a/testing/cffi0/test_ffi_backend.py b/testing/cffi0/test_ffi_backend.py
index 8e29bc4..2545d1f 100644
--- a/testing/cffi0/test_ffi_backend.py
+++ b/testing/cffi0/test_ffi_backend.py
@@ -1,4 +1,4 @@
-import py, sys, platform
+import sys, platform
import pytest
from testing.cffi0 import backend_tests, test_function, test_ownlib
from testing.support import u
@@ -18,7 +18,7 @@ class TestFFI(backend_tests.BackendTests,
def test_not_supported_bitfield_in_result(self):
ffi = FFI(backend=self.Backend())
ffi.cdef("struct foo_s { int a,b,c,d,e; int x:1; };")
- e = py.test.raises(NotImplementedError, ffi.callback,
+ e = pytest.raises(NotImplementedError, ffi.callback,
"struct foo_s foo(void)", lambda: 42)
assert str(e.value) == ("struct foo_s(*)(): "
"callback with unsupported argument or return type or with '...'")
@@ -37,7 +37,7 @@ class TestFFI(backend_tests.BackendTests,
assert ffi.typeof(p) == ffi.typeof("void *")
assert ffi.from_handle(p) is o
assert ffi.from_handle(ffi.cast("char *", p)) is o
- py.test.raises(RuntimeError, ffi.from_handle, ffi.NULL)
+ pytest.raises(RuntimeError, ffi.from_handle, ffi.NULL)
def test_callback_onerror(self):
ffi = FFI(backend=self.Backend())
@@ -105,29 +105,29 @@ class TestFFI(backend_tests.BackendTests,
def test_ffi_new_allocator_4(self):
ffi = FFI(backend=self.Backend())
- py.test.raises(TypeError, ffi.new_allocator, free=lambda x: None)
+ pytest.raises(TypeError, ffi.new_allocator, free=lambda x: None)
#
def myalloc2(size):
raise LookupError
alloc2 = ffi.new_allocator(myalloc2)
- py.test.raises(LookupError, alloc2, "int[5]")
+ pytest.raises(LookupError, alloc2, "int[5]")
#
def myalloc3(size):
return 42
alloc3 = ffi.new_allocator(myalloc3)
- e = py.test.raises(TypeError, alloc3, "int[5]")
+ e = pytest.raises(TypeError, alloc3, "int[5]")
assert str(e.value) == "alloc() must return a cdata object (got int)"
#
def myalloc4(size):
return ffi.cast("int", 42)
alloc4 = ffi.new_allocator(myalloc4)
- e = py.test.raises(TypeError, alloc4, "int[5]")
+ e = pytest.raises(TypeError, alloc4, "int[5]")
assert str(e.value) == "alloc() must return a cdata pointer, not 'int'"
#
def myalloc5(size):
return ffi.NULL
alloc5 = ffi.new_allocator(myalloc5)
- py.test.raises(MemoryError, alloc5, "int[5]")
+ pytest.raises(MemoryError, alloc5, "int[5]")
def test_new_struct_containing_struct_containing_array_varsize(self):
ffi = FFI(backend=self.Backend())
@@ -339,11 +339,11 @@ class TestBitfield:
q = ffi.cast("struct foo_s *", p)
assert q.x == 100
assert ffi.typeof(q.a) is ffi.typeof("int *") # no length recorded
- py.test.raises(TypeError, len, q.a)
+ pytest.raises(TypeError, len, q.a)
assert q.a[0] == 200
assert q.a[1] == 300
assert q.a[2] == 400
- py.test.raises(TypeError, list, q.a)
+ pytest.raises(TypeError, list, q.a)
@pytest.mark.skipif("sys.platform != 'win32'")
def test_getwinerror(self):
@@ -382,9 +382,9 @@ class TestBitfield:
assert p[2] == b"c"
#
assert p == ffi.from_buffer(b"abcd", require_writable=False)
- py.test.raises((TypeError, BufferError), ffi.from_buffer,
+ pytest.raises((TypeError, BufferError), ffi.from_buffer,
"char[]", b"abcd", True)
- py.test.raises((TypeError, BufferError), ffi.from_buffer, b"abcd",
+ pytest.raises((TypeError, BufferError), ffi.from_buffer, b"abcd",
require_writable=True)
def test_release(self):
@@ -442,7 +442,7 @@ class TestBitfield:
assert list(p) == [ord("a"), ord("b"), ord("c"), 0, 0]
ffi.memmove(p, bytearray(b"ABCDE"), 2)
assert list(p) == [ord("A"), ord("B"), ord("c"), 0, 0]
- py.test.raises((TypeError, BufferError), ffi.memmove, b"abcde", p, 3)
+ pytest.raises((TypeError, BufferError), ffi.memmove, b"abcde", p, 3)
ba = bytearray(b"xxxxx")
ffi.memmove(dest=ba, src=p, n=3)
assert ba == bytearray(b"ABcxx")
@@ -505,7 +505,7 @@ class TestBitfield:
def test_ffi_def_extern(self):
ffi = FFI()
- py.test.raises(ValueError, ffi.def_extern)
+ pytest.raises(ValueError, ffi.def_extern)
def test_introspect_typedef(self):
ffi = FFI()
@@ -565,19 +565,19 @@ class TestBitfield:
def test_negative_array_size(self):
ffi = FFI()
- py.test.raises(ValueError, ffi.cast, "int[-5]", 0)
+ pytest.raises(ValueError, ffi.cast, "int[-5]", 0)
def test_cannot_instantiate_manually(self):
ffi = FFI()
ct = type(ffi.typeof("void *"))
- py.test.raises(TypeError, ct)
- py.test.raises(TypeError, ct, ffi.NULL)
+ pytest.raises(TypeError, ct)
+ pytest.raises(TypeError, ct, ffi.NULL)
for cd in [type(ffi.cast("void *", 0)),
type(ffi.new("char[]", 3)),
type(ffi.gc(ffi.NULL, lambda x: None))]:
- py.test.raises(TypeError, cd)
- py.test.raises(TypeError, cd, ffi.NULL)
- py.test.raises(TypeError, cd, ffi.typeof("void *"))
+ pytest.raises(TypeError, cd)
+ pytest.raises(TypeError, cd, ffi.NULL)
+ pytest.raises(TypeError, cd, ffi.typeof("void *"))
def test_explicitly_defined_char16_t(self):
ffi = FFI()
diff --git a/testing/cffi0/test_function.py b/testing/cffi0/test_function.py
index 84d8db6..6e74157 100644
--- a/testing/cffi0/test_function.py
+++ b/testing/cffi0/test_function.py
@@ -1,4 +1,3 @@
-import py
import pytest
from cffi import FFI, CDefError
import math, os, sys
@@ -43,7 +42,7 @@ class TestFunction(object):
def test_sinf(self):
if sys.platform == 'win32':
- py.test.skip("no sinf found in the Windows stdlib")
+ pytest.skip("no sinf found in the Windows stdlib")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
float sinf(float x);
@@ -68,7 +67,7 @@ class TestFunction(object):
def test_dlopen_filename(self):
path = ctypes.util.find_library(lib_m)
if not path:
- py.test.skip("%s not found" % lib_m)
+ pytest.skip("%s not found" % lib_m)
ffi = FFI(backend=self.Backend())
ffi.cdef("""
double cos(double x);
@@ -104,9 +103,9 @@ class TestFunction(object):
def test_tlsalloc(self):
if sys.platform != 'win32':
- py.test.skip("win32 only")
+ pytest.skip("win32 only")
if self.Backend is CTypesBackend:
- py.test.skip("ctypes complains on wrong calling conv")
+ pytest.skip("ctypes complains on wrong calling conv")
ffi = FFI(backend=self.Backend())
ffi.cdef("long TlsAlloc(void); int TlsFree(long);")
lib = ffi.dlopen('KERNEL32.DLL')
@@ -117,7 +116,7 @@ class TestFunction(object):
def test_fputs(self):
if not sys.platform.startswith('linux'):
- py.test.skip("probably no symbol 'stderr' in the lib")
+ pytest.skip("probably no symbol 'stderr' in the lib")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
int fputs(const char *, void *);
@@ -134,7 +133,7 @@ class TestFunction(object):
def test_fputs_without_const(self):
if not sys.platform.startswith('linux'):
- py.test.skip("probably no symbol 'stderr' in the lib")
+ pytest.skip("probably no symbol 'stderr' in the lib")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
int fputs(char *, void *);
@@ -151,7 +150,7 @@ class TestFunction(object):
def test_vararg(self):
if not sys.platform.startswith('linux'):
- py.test.skip("probably no symbol 'stderr' in the lib")
+ pytest.skip("probably no symbol 'stderr' in the lib")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
int fprintf(void *, const char *format, ...);
@@ -190,7 +189,7 @@ class TestFunction(object):
""")
needs_dlopen_none()
ffi.C = ffi.dlopen(None)
- e = py.test.raises(TypeError, ffi.C.printf, b"hello %d\n", 42)
+ e = pytest.raises(TypeError, ffi.C.printf, b"hello %d\n", 42)
assert str(e.value) == ("argument 2 passed in the variadic part "
"needs to be a cdata object (got int)")
@@ -218,7 +217,7 @@ class TestFunction(object):
assert res == 42
#
if not sys.platform.startswith('linux'):
- py.test.skip("probably no symbol 'stderr' in the lib")
+ pytest.skip("probably no symbol 'stderr' in the lib")
ffi.cdef("""
int fputs(const char *, void *);
extern void *stderr;
@@ -250,7 +249,7 @@ class TestFunction(object):
def test_callback_returning_struct_three_bytes(self):
if self.Backend is CTypesBackend:
- py.test.skip("not supported with the ctypes backend")
+ pytest.skip("not supported with the ctypes backend")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
typedef struct {
@@ -278,7 +277,7 @@ class TestFunction(object):
def test_write_variable(self):
if not sys.platform.startswith('linux') or _is_musl:
- py.test.skip("probably no symbol 'stdout' in the lib")
+ pytest.skip("probably no symbol 'stdout' in the lib")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
extern void *stdout;
@@ -304,10 +303,10 @@ class TestFunction(object):
def test_function_with_struct_argument(self):
if sys.platform == 'win32':
- py.test.skip("no 'inet_ntoa'")
+ pytest.skip("no 'inet_ntoa'")
if (self.Backend is CTypesBackend and
'__pypy__' in sys.builtin_module_names):
- py.test.skip("ctypes limitation on pypy")
+ pytest.skip("ctypes limitation on pypy")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
struct in_addr { unsigned int s_addr; };
@@ -331,7 +330,7 @@ class TestFunction(object):
def test_fputs_custom_FILE(self):
if self.Backend is CTypesBackend:
- py.test.skip("FILE not supported with the ctypes backend")
+ pytest.skip("FILE not supported with the ctypes backend")
filename = str(udir.join('fputs_custom_FILE'))
ffi = FFI(backend=self.Backend())
ffi.cdef("int fputs(const char *, FILE *);")
@@ -370,7 +369,7 @@ class TestFunction(object):
def test_signed_char_star_accepts_string(self):
if self.Backend is CTypesBackend:
- py.test.skip("not supported by the ctypes backend")
+ pytest.skip("not supported by the ctypes backend")
ffi = FFI(backend=self.Backend())
ffi.cdef("""int strlen(signed char *);""")
needs_dlopen_none()
@@ -380,7 +379,7 @@ class TestFunction(object):
def test_unsigned_char_star_accepts_string(self):
if self.Backend is CTypesBackend:
- py.test.skip("not supported by the ctypes backend")
+ pytest.skip("not supported by the ctypes backend")
ffi = FFI(backend=self.Backend())
ffi.cdef("""int strlen(unsigned char *);""")
needs_dlopen_none()
@@ -414,7 +413,7 @@ class TestFunction(object):
def test_free_callback_cycle(self):
if self.Backend is CTypesBackend:
- py.test.skip("seems to fail with the ctypes backend on windows")
+ pytest.skip("seems to fail with the ctypes backend on windows")
import weakref
def make_callback(data):
container = [data]
@@ -437,9 +436,9 @@ class TestFunction(object):
def test_windows_stdcall(self):
if sys.platform != 'win32':
- py.test.skip("Windows-only test")
+ pytest.skip("Windows-only test")
if self.Backend is CTypesBackend:
- py.test.skip("not with the ctypes backend")
+ pytest.skip("not with the ctypes backend")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
BOOL QueryPerformanceFrequency(LONGLONG *lpFrequency);
@@ -452,9 +451,9 @@ class TestFunction(object):
def test_explicit_cdecl_stdcall(self):
if sys.platform != 'win32':
- py.test.skip("Windows-only test")
+ pytest.skip("Windows-only test")
if self.Backend is CTypesBackend:
- py.test.skip("not with the ctypes backend")
+ pytest.skip("not with the ctypes backend")
win64 = (sys.maxsize > 2**32)
#
ffi = FFI(backend=self.Backend())
@@ -500,8 +499,8 @@ class TestFunction(object):
fns = ffi.cast("fns_t", 0)
ffi.new("fnc_t[]", [fnc])
if not win64:
- py.test.raises(TypeError, ffi.new, "fnc_t[]", [fns])
- py.test.raises(TypeError, ffi.new, "fns_t[]", [fnc])
+ pytest.raises(TypeError, ffi.new, "fnc_t[]", [fns])
+ pytest.raises(TypeError, ffi.new, "fns_t[]", [fnc])
ffi.new("fns_t[]", [fns])
def test_stdcall_only_on_windows(self):
@@ -530,25 +529,25 @@ class TestFunction(object):
def test_dlclose(self):
if self.Backend is CTypesBackend:
- py.test.skip("not with the ctypes backend")
+ pytest.skip("not with the ctypes backend")
ffi = FFI(backend=self.Backend())
ffi.cdef("int foobar(void); extern int foobaz;")
lib = ffi.dlopen(lib_m)
ffi.dlclose(lib)
- e = py.test.raises(ValueError, getattr, lib, 'foobar')
+ e = pytest.raises(ValueError, getattr, lib, 'foobar')
assert str(e.value).startswith("library '")
assert str(e.value).endswith("' has already been closed")
- e = py.test.raises(ValueError, getattr, lib, 'foobaz')
+ e = pytest.raises(ValueError, getattr, lib, 'foobaz')
assert str(e.value).startswith("library '")
assert str(e.value).endswith("' has already been closed")
- e = py.test.raises(ValueError, setattr, lib, 'foobaz', 42)
+ e = pytest.raises(ValueError, setattr, lib, 'foobaz', 42)
assert str(e.value).startswith("library '")
assert str(e.value).endswith("' has already been closed")
ffi.dlclose(lib) # does not raise
def test_passing_large_list(self):
if self.Backend is CTypesBackend:
- py.test.skip("the ctypes backend doesn't support this")
+ pytest.skip("the ctypes backend doesn't support this")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
void getenv(char *);
diff --git a/testing/cffi0/test_ownlib.py b/testing/cffi0/test_ownlib.py
index bbdab8c..e1a61d6 100644
--- a/testing/cffi0/test_ownlib.py
+++ b/testing/cffi0/test_ownlib.py
@@ -1,5 +1,6 @@
-import py, sys, os
+import sys, os
import subprocess, weakref
+import pytest
from cffi import FFI
from cffi.backend_ctypes import CTypesBackend
from testing.support import u, is_musl
@@ -180,9 +181,9 @@ class TestOwnLib(object):
def test_getting_errno(self):
if self.module is None:
- py.test.skip("fix the auto-generation of the tiny test lib")
+ pytest.skip("fix the auto-generation of the tiny test lib")
if sys.platform == 'win32':
- py.test.skip("fails, errno at multiple addresses")
+ pytest.skip("fails, errno at multiple addresses")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
int test_getting_errno(void);
@@ -194,11 +195,11 @@ class TestOwnLib(object):
def test_setting_errno(self):
if self.module is None:
- py.test.skip("fix the auto-generation of the tiny test lib")
+ pytest.skip("fix the auto-generation of the tiny test lib")
if sys.platform == 'win32':
- py.test.skip("fails, errno at multiple addresses")
+ pytest.skip("fails, errno at multiple addresses")
if self.Backend is CTypesBackend and '__pypy__' in sys.modules:
- py.test.skip("XXX errno issue with ctypes on pypy?")
+ pytest.skip("XXX errno issue with ctypes on pypy?")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
int test_setting_errno(void);
@@ -211,7 +212,7 @@ class TestOwnLib(object):
def test_my_array_7(self):
if self.module is None:
- py.test.skip("fix the auto-generation of the tiny test lib")
+ pytest.skip("fix the auto-generation of the tiny test lib")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
extern int my_array[7];
@@ -221,7 +222,7 @@ class TestOwnLib(object):
assert ownlib.my_array[i] == i
assert len(ownlib.my_array) == 7
if self.Backend is CTypesBackend:
- py.test.skip("not supported by the ctypes backend")
+ pytest.skip("not supported by the ctypes backend")
ownlib.my_array = list(range(10, 17))
for i in range(7):
assert ownlib.my_array[i] == 10 + i
@@ -231,9 +232,9 @@ class TestOwnLib(object):
def test_my_array_no_length(self):
if self.module is None:
- py.test.skip("fix the auto-generation of the tiny test lib")
+ pytest.skip("fix the auto-generation of the tiny test lib")
if self.Backend is CTypesBackend:
- py.test.skip("not supported by the ctypes backend")
+ pytest.skip("not supported by the ctypes backend")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
extern int my_array[];
@@ -241,7 +242,7 @@ class TestOwnLib(object):
ownlib = ffi.dlopen(self.module)
for i in range(7):
assert ownlib.my_array[i] == i
- py.test.raises(TypeError, len, ownlib.my_array)
+ pytest.raises(TypeError, len, ownlib.my_array)
ownlib.my_array = list(range(10, 17))
for i in range(7):
assert ownlib.my_array[i] == 10 + i
@@ -251,7 +252,7 @@ class TestOwnLib(object):
def test_keepalive_lib(self):
if self.module is None:
- py.test.skip("fix the auto-generation of the tiny test lib")
+ pytest.skip("fix the auto-generation of the tiny test lib")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
int test_getting_errno(void);
@@ -269,7 +270,7 @@ class TestOwnLib(object):
def test_keepalive_ffi(self):
if self.module is None:
- py.test.skip("fix the auto-generation of the tiny test lib")
+ pytest.skip("fix the auto-generation of the tiny test lib")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
int test_getting_errno(void);
@@ -289,7 +290,7 @@ class TestOwnLib(object):
def test_struct_by_value(self):
if self.module is None:
- py.test.skip("fix the auto-generation of the tiny test lib")
+ pytest.skip("fix the auto-generation of the tiny test lib")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
typedef struct {
@@ -330,9 +331,9 @@ class TestOwnLib(object):
def test_addressof_lib(self):
if self.module is None:
- py.test.skip("fix the auto-generation of the tiny test lib")
+ pytest.skip("fix the auto-generation of the tiny test lib")
if self.Backend is CTypesBackend:
- py.test.skip("not implemented with the ctypes backend")
+ pytest.skip("not implemented with the ctypes backend")
ffi = FFI(backend=self.Backend())
ffi.cdef("extern long left; int test_getting_errno(void);")
lib = ffi.dlopen(self.module)
@@ -348,9 +349,9 @@ class TestOwnLib(object):
def test_char16_char32_t(self):
if self.module is None:
- py.test.skip("fix the auto-generation of the tiny test lib")
+ pytest.skip("fix the auto-generation of the tiny test lib")
if self.Backend is CTypesBackend:
- py.test.skip("not implemented with the ctypes backend")
+ pytest.skip("not implemented with the ctypes backend")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
char16_t foo_2bytes(char16_t);
@@ -363,9 +364,9 @@ class TestOwnLib(object):
def test_modify_struct_value(self):
if self.module is None:
- py.test.skip("fix the auto-generation of the tiny test lib")
+ pytest.skip("fix the auto-generation of the tiny test lib")
if self.Backend is CTypesBackend:
- py.test.skip("fails with the ctypes backend on some architectures")
+ pytest.skip("fails with the ctypes backend on some architectures")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
typedef struct {
@@ -387,11 +388,11 @@ class TestOwnLib(object):
def test_dlopen_handle(self):
if self.module is None:
- py.test.skip("fix the auto-generation of the tiny test lib")
+ pytest.skip("fix the auto-generation of the tiny test lib")
if sys.platform == 'win32' or is_musl:
- py.test.skip("uses 'dl' explicitly")
+ pytest.skip("uses 'dl' explicitly")
if self.__class__.Backend is CTypesBackend:
- py.test.skip("not for the ctypes backend")
+ pytest.skip("not for the ctypes backend")
backend = self.Backend()
ffi1 = FFI(backend=backend)
ffi1.cdef("""void *dlopen(const char *filename, int flags);
@@ -413,9 +414,9 @@ class TestOwnLib(object):
def test_return_three_bytes(self):
if self.module is None:
- py.test.skip("fix the auto-generation of the tiny test lib")
+ pytest.skip("fix the auto-generation of the tiny test lib")
if self.__class__.Backend is CTypesBackend:
- py.test.skip("not working on win32 on the ctypes backend")
+ pytest.skip("not working on win32 on the ctypes backend")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
typedef struct {
diff --git a/testing/cffi0/test_parsing.py b/testing/cffi0/test_parsing.py
index 5d93a8d..af6293e 100644
--- a/testing/cffi0/test_parsing.py
+++ b/testing/cffi0/test_parsing.py
@@ -1,4 +1,5 @@
-import py, sys, re
+import sys, re
+import pytest
from cffi import FFI, FFIError, CDefError, VerificationError
from .backend_tests import needs_dlopen_none
from testing.support import is_musl
@@ -191,14 +192,14 @@ def test_remove_line_continuation_comments():
def test_dont_remove_comment_in_line_directives():
ffi = FFI(backend=FakeBackend())
- e = py.test.raises(CDefError, ffi.cdef, """
+ e = pytest.raises(CDefError, ffi.cdef, """
\t # \t line \t 8 \t "baz.c" \t
some syntax error here
""")
assert str(e.value) == "parse error\nbaz.c:9:14: before: syntax"
#
- e = py.test.raises(CDefError, ffi.cdef, """
+ e = pytest.raises(CDefError, ffi.cdef, """
#line 7 "foo//bar.c"
some syntax error here
@@ -206,14 +207,14 @@ def test_dont_remove_comment_in_line_directives():
#
assert str(e.value) == "parse error\nfoo//bar.c:8:14: before: syntax"
ffi = FFI(backend=FakeBackend())
- e = py.test.raises(CDefError, ffi.cdef, """
+ e = pytest.raises(CDefError, ffi.cdef, """
\t # \t 8 \t "baz.c" \t
some syntax error here
""")
assert str(e.value) == "parse error\nbaz.c:9:14: before: syntax"
#
- e = py.test.raises(CDefError, ffi.cdef, """
+ e = pytest.raises(CDefError, ffi.cdef, """
# 7 "foo//bar.c"
some syntax error here
@@ -222,7 +223,7 @@ def test_dont_remove_comment_in_line_directives():
def test_multiple_line_directives():
ffi = FFI(backend=FakeBackend())
- e = py.test.raises(CDefError, ffi.cdef,
+ e = pytest.raises(CDefError, ffi.cdef,
""" #line 5 "foo.c"
extern int xx;
#line 6 "bar.c"
@@ -234,7 +235,7 @@ def test_multiple_line_directives():
""")
assert str(e.value) == "parse error\nbaz.c:7:14: before: syntax"
#
- e = py.test.raises(CDefError, ffi.cdef,
+ e = pytest.raises(CDefError, ffi.cdef,
""" # 5 "foo.c"
extern int xx;
# 6 "bar.c"
@@ -248,7 +249,7 @@ def test_multiple_line_directives():
def test_commented_line_directive():
ffi = FFI(backend=FakeBackend())
- e = py.test.raises(CDefError, ffi.cdef, """
+ e = pytest.raises(CDefError, ffi.cdef, """
/*
#line 5 "foo.c"
*/
@@ -262,7 +263,7 @@ def test_commented_line_directive():
""")
#
assert str(e.value) == "parse error\nbar.c:9:14: before: syntax"
- e = py.test.raises(CDefError, ffi.cdef, """
+ e = pytest.raises(CDefError, ffi.cdef, """
/*
# 5 "foo.c"
*/
@@ -290,7 +291,7 @@ def test_line_continuation_in_defines():
def test_define_not_supported_for_now():
ffi = FFI(backend=FakeBackend())
- e = py.test.raises(CDefError, ffi.cdef, '#define FOO "blah"')
+ e = pytest.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'
@@ -310,7 +311,7 @@ def test_unnamed_struct():
type_bar = ffi._parser.parse_type("bar_p").totype
assert repr(type_foo) == "<foo_t>"
assert repr(type_bar) == "<struct $1>"
- py.test.raises(VerificationError, type_bar.get_c_name)
+ pytest.raises(VerificationError, type_bar.get_c_name)
assert type_foo.get_c_name() == "foo_t"
def test_override():
@@ -318,7 +319,7 @@ def test_override():
needs_dlopen_none()
C = ffi.dlopen(None)
ffi.cdef("int foo(void);")
- py.test.raises(FFIError, ffi.cdef, "long foo(void);")
+ pytest.raises(FFIError, ffi.cdef, "long foo(void);")
assert C.foo.BType == '<func (), <int>, False>'
ffi.cdef("long foo(void);", override=True)
assert C.foo.BType == '<func (), <long>, False>'
@@ -326,23 +327,23 @@ def test_override():
def test_cannot_have_only_variadic_part():
# this checks that we get a sensible error if we try "int foo(...);"
ffi = FFI()
- e = py.test.raises(CDefError, ffi.cdef, "int foo(...);")
+ e = pytest.raises(CDefError, ffi.cdef, "int foo(...);")
assert str(e.value) == (
"<cdef source string>:1: foo: a function with only '(...)' "
"as argument is not correct C")
def test_parse_error():
ffi = FFI()
- e = py.test.raises(CDefError, ffi.cdef, " x y z ")
+ e = pytest.raises(CDefError, ffi.cdef, " x y z ")
assert str(e.value).startswith(
'cannot parse "x y z"\n<cdef source string>:1:')
- e = py.test.raises(CDefError, ffi.cdef, "\n\n\n x y z ")
+ e = pytest.raises(CDefError, ffi.cdef, "\n\n\n x y z ")
assert str(e.value).startswith(
'cannot parse "x y z"\n<cdef source string>:4:')
def test_error_custom_lineno():
ffi = FFI()
- e = py.test.raises(CDefError, ffi.cdef, """
+ e = pytest.raises(CDefError, ffi.cdef, """
# 42 "foobar"
a b c d
@@ -351,7 +352,7 @@ def test_error_custom_lineno():
def test_cannot_declare_enum_later():
ffi = FFI()
- e = py.test.raises(NotImplementedError, ffi.cdef,
+ e = pytest.raises(NotImplementedError, ffi.cdef,
"typedef enum foo_e foo_t; enum foo_e { AA, BB };")
assert str(e.value) == (
"enum foo_e: the '{}' declaration should appear on the "
@@ -359,11 +360,11 @@ def test_cannot_declare_enum_later():
def test_unknown_name():
ffi = FFI()
- e = py.test.raises(CDefError, ffi.cast, "foobarbazunknown", 0)
+ e = pytest.raises(CDefError, ffi.cast, "foobarbazunknown", 0)
assert str(e.value) == "unknown identifier 'foobarbazunknown'"
- e = py.test.raises(CDefError, ffi.cast, "foobarbazunknown*", 0)
+ e = pytest.raises(CDefError, ffi.cast, "foobarbazunknown*", 0)
assert str(e.value).startswith('cannot parse "foobarbazunknown*"')
- e = py.test.raises(CDefError, ffi.cast, "int(*)(foobarbazunknown)", 0)
+ e = pytest.raises(CDefError, ffi.cast, "int(*)(foobarbazunknown)", 0)
assert str(e.value).startswith('cannot parse "int(*)(foobarbazunknown)"')
def test_redefine_common_type():
@@ -390,7 +391,7 @@ def test_bool():
def test_unknown_argument_type():
ffi = FFI()
- e = py.test.raises(CDefError, ffi.cdef, "void f(foobarbazzz);")
+ e = pytest.raises(CDefError, ffi.cdef, "void f(foobarbazzz);")
assert str(e.value) == ("<cdef source string>:1: f arg 1:"
" unknown type 'foobarbazzz' (if you meant"
" to use the old C syntax of giving untyped"
@@ -405,7 +406,7 @@ def test_void_renamed_as_only_arg():
def test_WPARAM_on_windows():
if sys.platform != 'win32':
- py.test.skip("Only for Windows")
+ pytest.skip("Only for Windows")
ffi = FFI()
ffi.cdef("void f(WPARAM);")
#
@@ -572,7 +573,7 @@ def test_extern_python_group():
def test_error_invalid_syntax_for_cdef():
ffi = FFI()
- e = py.test.raises(CDefError, ffi.cdef, 'void foo(void) {}')
+ e = pytest.raises(CDefError, ffi.cdef, 'void foo(void) {}')
assert str(e.value) == ('<cdef source string>:1: unexpected <FuncDef>: '
'this construct is valid C but not valid in cdef()')
diff --git a/testing/cffi0/test_verify.py b/testing/cffi0/test_verify.py
index de1608d..96d752d 100644
--- a/testing/cffi0/test_verify.py
+++ b/testing/cffi0/test_verify.py
@@ -1,4 +1,4 @@
-import py, re
+import re
import pytest
import sys, os, math, weakref
from cffi import FFI, VerificationError, VerificationMissing, model, FFIError
@@ -84,10 +84,10 @@ def test_simple_case():
def _Wconversion(cdef, source, **kargs):
if sys.platform in ('win32', 'darwin'):
- py.test.skip("needs GCC")
+ pytest.skip("needs GCC")
ffi = FFI()
ffi.cdef(cdef)
- py.test.raises(VerificationError, ffi.verify, source, **kargs)
+ pytest.raises(VerificationError, ffi.verify, source, **kargs)
extra_compile_args_orig = extra_compile_args[:]
extra_compile_args.remove('-Wconversion')
try:
@@ -207,7 +207,7 @@ def test_longdouble_precision():
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'")
+ pytest.skip("don't know the very exact precision of 'long double'")
all_primitive_types = model.PrimitiveType.ALL_PRIMITIVE_TYPES
@@ -260,7 +260,7 @@ def test_all_integer_and_float_types():
if sys.version < '3':
assert foo(long(44)) == 45
assert foo(ffi.cast(typename, 46)) == 47
- py.test.raises(TypeError, foo, ffi.NULL)
+ pytest.raises(TypeError, foo, ffi.NULL)
#
# check for overflow cases
if all_primitive_types[typename] == 'f':
@@ -269,7 +269,7 @@ def test_all_integer_and_float_types():
2**5, 2**10, 2**20, 2**40, 2**80]:
overflows = int(ffi.cast(typename, value)) != value
if overflows:
- py.test.raises(OverflowError, foo, value)
+ pytest.raises(OverflowError, foo, value)
else:
assert foo(value) == value + 1
@@ -289,8 +289,8 @@ def test_var_signed_integer_types():
assert getattr(lib, varname) == max
setattr(lib, varname, min)
assert getattr(lib, varname) == min
- py.test.raises(OverflowError, setattr, lib, varname, max+1)
- py.test.raises(OverflowError, setattr, lib, varname, min-1)
+ pytest.raises(OverflowError, setattr, lib, varname, max+1)
+ pytest.raises(OverflowError, setattr, lib, varname, min-1)
def test_var_unsigned_integer_types():
ffi = FFI()
@@ -310,8 +310,8 @@ def test_var_unsigned_integer_types():
assert getattr(lib, varname) == max
setattr(lib, varname, 0)
assert getattr(lib, varname) == 0
- py.test.raises(OverflowError, setattr, lib, varname, max+1)
- py.test.raises(OverflowError, setattr, lib, varname, -1)
+ pytest.raises(OverflowError, setattr, lib, varname, max+1)
+ pytest.raises(OverflowError, setattr, lib, varname, -1)
def test_fn_signed_integer_types():
ffi = FFI()
@@ -330,8 +330,8 @@ def test_fn_signed_integer_types():
fn = getattr(lib, fnname)
assert fn(max) == max
assert fn(min) == min
- py.test.raises(OverflowError, fn, max + 1)
- py.test.raises(OverflowError, fn, min - 1)
+ pytest.raises(OverflowError, fn, max + 1)
+ pytest.raises(OverflowError, fn, min - 1)
def test_fn_unsigned_integer_types():
ffi = FFI()
@@ -352,16 +352,16 @@ def test_fn_unsigned_integer_types():
fn = getattr(lib, fnname)
assert fn(max) == max
assert fn(0) == 0
- py.test.raises(OverflowError, fn, max + 1)
- py.test.raises(OverflowError, fn, -1)
+ pytest.raises(OverflowError, fn, max + 1)
+ pytest.raises(OverflowError, fn, -1)
def test_char_type():
ffi = FFI()
ffi.cdef("char foo(char);")
lib = ffi.verify("char foo(char x) { return ++x; }")
assert lib.foo(b"A") == b"B"
- py.test.raises(TypeError, lib.foo, b"bar")
- py.test.raises(TypeError, lib.foo, "bar")
+ pytest.raises(TypeError, lib.foo, b"bar")
+ pytest.raises(TypeError, lib.foo, "bar")
def test_wchar_type():
ffi = FFI()
@@ -377,7 +377,7 @@ def test_wchar_type():
assert lib.foo(uniexample1) == uniexample2
def test_char16_char32_type():
- py.test.skip("XXX test or fully prevent char16_t and char32_t from "
+ pytest.skip("XXX test or fully prevent char16_t and char32_t from "
"working in ffi.verify() mode")
def test_no_argument():
@@ -412,11 +412,11 @@ def test_bogus_ptr():
ffi = FFI()
ffi.cdef("int *foo(int *);")
lib = ffi.verify("int *foo(int *a) { return a; }")
- py.test.raises(TypeError, lib.foo, ffi.new("short *", 42))
+ pytest.raises(TypeError, lib.foo, ffi.new("short *", 42))
def test_verify_typedefs():
- py.test.skip("ignored so far")
+ pytest.skip("ignored so far")
types = ['signed char', 'unsigned char', 'int', 'long']
for cdefed in types:
for real in types:
@@ -425,7 +425,7 @@ def test_verify_typedefs():
if cdefed == real:
ffi.verify("typedef %s foo_t;" % real)
else:
- py.test.raises(VerificationError, ffi.verify,
+ pytest.raises(VerificationError, ffi.verify,
"typedef %s foo_t;" % real)
def test_nondecl_struct():
@@ -441,19 +441,19 @@ def test_ffi_full_struct():
ffi.verify("struct foo_s { char x; int y; long *z; };")
#
if sys.platform != 'win32': # XXX fixme: only gives warnings
- py.test.raises(VerificationError, ffi.verify,
+ pytest.raises(VerificationError, ffi.verify,
"struct foo_s { char x; int y; int *z; };")
#
- py.test.raises(VerificationError, ffi.verify,
+ pytest.raises(VerificationError, ffi.verify,
"struct foo_s { int y; long *z; };")
#
- e = py.test.raises(VerificationError, ffi.verify,
+ e = pytest.raises(VerificationError, ffi.verify,
"struct foo_s { int y; char x; long *z; };")
assert str(e.value) == (
"struct foo_s: wrong offset for field 'x'"
" (we have 0, but C compiler says 4)")
#
- e = py.test.raises(VerificationError, ffi.verify,
+ e = pytest.raises(VerificationError, ffi.verify,
"struct foo_s { char x; int y; long *z; char extra; };")
assert str(e.value) == (
"struct foo_s: wrong total size"
@@ -466,7 +466,7 @@ def test_ffi_full_struct():
# that replaces what is just padding in our declaration above
ffi.verify("struct foo_s { char x, extra; int y; long *z; };")
#
- e = py.test.raises(VerificationError, ffi.verify,
+ e = pytest.raises(VerificationError, ffi.verify,
"struct foo_s { char x; short pad; short y; long *z; };")
assert str(e.value) == (
"struct foo_s: wrong size for field 'y'"
@@ -480,9 +480,9 @@ def test_ffi_nonfull_struct():
...;
};
""")
- py.test.raises(VerificationMissing, ffi.sizeof, 'struct foo_s')
- py.test.raises(VerificationMissing, ffi.offsetof, 'struct foo_s', 'x')
- py.test.raises(VerificationMissing, ffi.new, 'struct foo_s *')
+ pytest.raises(VerificationMissing, ffi.sizeof, 'struct foo_s')
+ pytest.raises(VerificationMissing, ffi.offsetof, 'struct foo_s', 'x')
+ pytest.raises(VerificationMissing, ffi.new, 'struct foo_s *')
ffi.verify("""
struct foo_s {
int a, b, x, c, d, e;
@@ -535,7 +535,7 @@ def test_struct_signedness_ignored():
def test_struct_float_vs_int():
if sys.platform == 'win32':
- py.test.skip("XXX fixme: only gives warnings")
+ pytest.skip("XXX fixme: only gives warnings")
ffi = FFI()
for typename in all_signed_integer_types(ffi):
for real in all_float_types:
@@ -586,7 +586,7 @@ def test_struct_array_guess_length():
def test_struct_array_c99_1():
if sys.platform == 'win32':
- py.test.skip("requires C99")
+ pytest.skip("requires C99")
ffi = FFI()
ffi.cdef("struct foo_s { int x; int a[]; };")
ffi.verify("struct foo_s { int x; int a[]; };")
@@ -609,7 +609,7 @@ def test_struct_array_c99_1():
def test_struct_array_c99_2():
if sys.platform == 'win32':
- py.test.skip("requires C99")
+ pytest.skip("requires C99")
ffi = FFI()
ffi.cdef("struct foo_s { int x; int a[]; ...; };")
ffi.verify("struct foo_s { int x, y; int a[]; };")
@@ -658,7 +658,7 @@ def test_struct_with_bitfield_enum():
def test_unsupported_struct_with_bitfield_ellipsis():
ffi = FFI()
- py.test.raises(NotImplementedError, ffi.cdef,
+ pytest.raises(NotImplementedError, ffi.cdef,
"struct foo_s { int a:2, b:3; ...; };")
def test_global_constants():
@@ -705,7 +705,7 @@ def test_global_constants_non_int():
def test_nonfull_enum():
ffi = FFI()
ffi.cdef("enum ee { EE1, EE2, EE3, ... \n \t };")
- py.test.raises(VerificationMissing, ffi.cast, 'enum ee', 'EE2')
+ pytest.raises(VerificationMissing, ffi.cast, 'enum ee', 'EE2')
ffi.verify("enum ee { EE1=10, EE2, EE3=-10, EE4 };")
assert ffi.string(ffi.cast('enum ee', 11)) == "EE2"
assert ffi.string(ffi.cast('enum ee', -10)) == "EE3"
@@ -721,8 +721,8 @@ def test_full_enum():
ffi = FFI()
ffi.cdef("enum ee { EE1, EE2, EE3 };")
ffi.verify("enum ee { EE1, EE2, EE3 };")
- py.test.raises(VerificationError, ffi.verify, "enum ee { EE1, EE2 };")
- e = py.test.raises(VerificationError, ffi.verify,
+ pytest.raises(VerificationError, ffi.verify, "enum ee { EE1, EE2 };")
+ e = pytest.raises(VerificationError, ffi.verify,
"enum ee { EE1, EE3, EE2 };")
assert str(e.value) == 'enum ee: EE2 has the real value 2, not 1'
# extra items cannot be seen and have no bad consequence anyway
@@ -757,14 +757,14 @@ def test_nonfull_anonymous_enum():
def test_nonfull_enum_syntax2():
ffi = FFI()
ffi.cdef("enum ee { EE1, EE2=\t..., EE3 };")
- py.test.raises(VerificationMissing, ffi.cast, 'enum ee', 'EE1')
+ pytest.raises(VerificationMissing, ffi.cast, 'enum ee', 'EE1')
ffi.verify("enum ee { EE1=10, EE2, EE3=-10, EE4 };")
assert ffi.string(ffi.cast('enum ee', 11)) == 'EE2'
assert ffi.string(ffi.cast('enum ee', -10)) == 'EE3'
#
ffi = FFI()
ffi.cdef("enum ee { EE1, EE2=\t... };")
- py.test.raises(VerificationMissing, ffi.cast, 'enum ee', 'EE1')
+ pytest.raises(VerificationMissing, ffi.cast, 'enum ee', 'EE1')
ffi.verify("enum ee { EE1=10, EE2, EE3=-10, EE4 };")
assert ffi.string(ffi.cast('enum ee', 11)) == 'EE2'
#
@@ -851,7 +851,7 @@ def test_access_array_variable(length=5):
# work with array instances whose length we know. using a pointer
# instead of an array gives the correct effects.
assert repr(lib.somenumber).startswith("<cdata 'int *' 0x")
- py.test.raises(TypeError, len, lib.somenumber)
+ pytest.raises(TypeError, len, lib.somenumber)
else:
assert repr(lib.somenumber).startswith("<cdata 'int[%s]' 0x" % length)
assert len(lib.somenumber) == 5
@@ -1016,10 +1016,10 @@ def test_varargs():
def test_varargs_exact():
if sys.platform == 'win32':
- py.test.skip("XXX fixme: only gives warnings")
+ pytest.skip("XXX fixme: only gives warnings")
ffi = FFI()
ffi.cdef("int foo(int x, ...);")
- py.test.raises(VerificationError, ffi.verify, """
+ pytest.raises(VerificationError, ffi.verify, """
int foo(long long x, ...) {
return x;
}
@@ -1075,7 +1075,7 @@ def test_autofilled_struct_as_argument_dynamic():
}
static int (*foo)(struct foo_s s) = &foo1;
""")
- e = py.test.raises(NotImplementedError, lib.foo, "?")
+ e = pytest.raises(NotImplementedError, lib.foo, "?")
msg = ("ctype 'struct foo_s' not supported as argument. It is a struct "
'declared with "...;", but the C calling convention may depend on '
"the missing fields; or, it contains anonymous struct/unions. "
@@ -1152,7 +1152,7 @@ def test_enum_as_argument():
int foo_func(enum foo_e e) { return (int)e; }
""")
assert lib.foo_func(lib.BB) == 2
- py.test.raises(TypeError, lib.foo_func, "BB")
+ pytest.raises(TypeError, lib.foo_func, "BB")
def test_enum_as_function_result():
ffi = FFI()
@@ -1185,7 +1185,7 @@ def test_typedef_complete_enum():
def test_typedef_broken_complete_enum():
ffi = FFI()
ffi.cdef("typedef enum { AA, BB } enum1_t;")
- py.test.raises(VerificationError, ffi.verify,
+ pytest.raises(VerificationError, ffi.verify,
"typedef enum { AA, CC, BB } enum1_t;")
def test_typedef_incomplete_enum():
@@ -1208,7 +1208,7 @@ def test_typedef_enum_as_argument():
int foo_func(foo_t e) { return (int)e; }
""")
assert lib.foo_func(lib.BB) == lib.BB == 2
- py.test.raises(TypeError, lib.foo_func, "BB")
+ pytest.raises(TypeError, lib.foo_func, "BB")
def test_typedef_enum_as_function_result():
ffi = FFI()
@@ -1234,9 +1234,9 @@ def test_function_typedef():
def test_opaque_integer_as_function_result():
#import platform
#if platform.machine().startswith('sparc'):
- # py.test.skip('Breaks horribly on sparc (SIGILL + corrupted stack)')
+ # pytest.skip('Breaks horribly on sparc (SIGILL + corrupted stack)')
#elif platform.machine() == 'mips64' and sys.maxsize > 2**32:
- # py.test.skip('Segfaults on mips64el')
+ # pytest.skip('Segfaults on mips64el')
# XXX bad abuse of "struct { ...; }". It only works a bit by chance
# anyway. XXX think about something better :-(
ffi = FFI()
@@ -1288,7 +1288,7 @@ def test_take_and_return_partial_structs():
def test_cannot_name_struct_type():
ffi = FFI()
ffi.cdef("typedef struct { int x; } **sp; void foo(sp);")
- e = py.test.raises(VerificationError, ffi.verify,
+ e = pytest.raises(VerificationError, ffi.verify,
"typedef struct { int x; } **sp; void foo(sp x) { }")
assert 'in argument of foo: unknown type name' in str(e.value)
@@ -1300,7 +1300,7 @@ def test_dont_check_unnamable_fields():
def test_nested_anonymous_struct_exact():
if sys.platform == 'win32':
- py.test.skip("nested anonymous struct/union")
+ pytest.skip("nested anonymous struct/union")
ffi = FFI()
ffi.cdef("""
struct foo_s { struct { int a; char b; }; union { char c, d; }; };
@@ -1320,15 +1320,15 @@ def test_nested_anonymous_struct_exact():
def test_nested_anonymous_struct_exact_error():
if sys.platform == 'win32':
- py.test.skip("nested anonymous struct/union")
+ pytest.skip("nested anonymous struct/union")
ffi = FFI()
ffi.cdef("""
struct foo_s { struct { int a; char b; }; union { char c, d; }; };
""")
- py.test.raises(VerificationError, ffi.verify, """
+ pytest.raises(VerificationError, ffi.verify, """
struct foo_s { struct { int a; short b; }; union { char c, d; }; };
""")
- py.test.raises(VerificationError, ffi.verify, """
+ pytest.raises(VerificationError, ffi.verify, """
struct foo_s { struct { int a; char e, b; }; union { char c, d; }; };
""")
@@ -1389,7 +1389,7 @@ def test_ffi_union_with_partial_struct_2():
def test_ffi_struct_packed():
if sys.platform == 'win32':
- py.test.skip("needs a GCC extension")
+ pytest.skip("needs a GCC extension")
ffi = FFI()
ffi.cdef("struct foo_s { int b; ...; };")
ffi.verify("""
@@ -1440,7 +1440,7 @@ def test_bug1():
def test_bool():
if sys.platform == 'win32':
- py.test.skip("_Bool not in MSVC")
+ pytest.skip("_Bool not in MSVC")
ffi = FFI()
ffi.cdef("struct foo_s { _Bool x; };"
"_Bool foo(_Bool); static _Bool (*foop)(_Bool);")
@@ -1464,13 +1464,13 @@ def test_bool():
assert lib.foop(1) is False
assert lib.foop(True) is False
assert lib.foop(0) is True
- py.test.raises(OverflowError, lib.foop, 42)
- py.test.raises(TypeError, lib.foop, 0.0)
+ pytest.raises(OverflowError, lib.foop, 42)
+ pytest.raises(TypeError, lib.foop, 0.0)
assert lib.foo(1) is False
assert lib.foo(True) is False
assert lib.foo(0) is True
- py.test.raises(OverflowError, lib.foo, 42)
- py.test.raises(TypeError, lib.foo, 0.0)
+ pytest.raises(OverflowError, lib.foo, 42)
+ pytest.raises(TypeError, lib.foo, 0.0)
assert int(ffi.cast("_Bool", long(1))) == 1
assert int(ffi.cast("_Bool", long(0))) == 0
assert int(ffi.cast("_Bool", long(-1))) == 1
@@ -1491,14 +1491,14 @@ def test_bool():
assert int(ffi.cast("_Bool", f)) == 0
assert f.seen
#
- py.test.raises(TypeError, ffi.cast, "_Bool", [])
+ pytest.raises(TypeError, ffi.cast, "_Bool", [])
def test_bool_on_long_double():
if sys.platform == 'win32':
- py.test.skip("_Bool not in MSVC")
+ pytest.skip("_Bool not in MSVC")
f = 1E-250
if f == 0.0 or f*f != 0.0:
- py.test.skip("unexpected precision")
+ pytest.skip("unexpected precision")
ffi = FFI()
ffi.cdef("long double square(long double f); _Bool opposite(_Bool);")
lib = ffi.verify("long double square(long double f) { return f*f; }\n"
@@ -1507,12 +1507,12 @@ def test_bool_on_long_double():
f2 = lib.square(f)
f3 = lib.square(f * 2.0)
if repr(f2) == repr(f3):
- py.test.skip("long double doesn't have enough precision")
+ pytest.skip("long double doesn't have enough precision")
assert float(f0) == float(f2) == float(f3) == 0.0 # too tiny for 'double'
assert int(ffi.cast("_Bool", f2)) == 1
assert int(ffi.cast("_Bool", f3)) == 1
assert int(ffi.cast("_Bool", f0)) == 0
- py.test.raises(TypeError, lib.opposite, f2)
+ pytest.raises(TypeError, lib.opposite, f2)
def test_cannot_pass_float():
for basetype in ['char', 'short', 'int', 'long', 'long long']:
@@ -1532,7 +1532,7 @@ def test_cannot_pass_float():
p.x = 0.0
assert lib.foo(42) == 0
assert lib.foo(0) == 1
- py.test.raises(TypeError, lib.foo, 0.0)
+ pytest.raises(TypeError, lib.foo, 0.0)
def test_cast_from_int_type_to_bool():
ffi = FFI()
@@ -1563,18 +1563,18 @@ def test_addressof():
p = ffi.new("struct foo_s *")
p.point.x = 16
p.point.y = 9
- py.test.raises(TypeError, lib.sum_coord, p.point)
+ pytest.raises(TypeError, lib.sum_coord, p.point)
res = lib.sum_coord(ffi.addressof(p.point))
assert res.x == 25
assert res.y == 7
res2 = lib.sum_coord(ffi.addressof(res))
assert res2.x == 32
assert res2.y == 18
- py.test.raises(TypeError, lib.sum_coord, res2)
+ pytest.raises(TypeError, lib.sum_coord, res2)
def test_callback_in_thread():
if sys.platform == 'win32':
- py.test.skip("pthread only")
+ pytest.skip("pthread only")
import os, subprocess, imp
arg = os.path.join(os.path.dirname(__file__), 'callback_in_thread.py')
g = subprocess.Popen([sys.executable, arg,
@@ -1610,7 +1610,7 @@ def test_keepalive_ffi():
def test_FILE_stored_in_stdout():
if not sys.platform.startswith('linux') or is_musl:
- py.test.skip("likely, we cannot assign to stdout")
+ pytest.skip("likely, we cannot assign to stdout")
ffi = FFI()
ffi.cdef("int printf(const char *, ...); FILE *setstdout(FILE *);")
lib = ffi.verify("""
@@ -1682,7 +1682,7 @@ def test_global_array_with_dotdotdot_length():
def test_bad_global_array_with_dotdotdot_length():
ffi = FFI()
ffi.cdef("extern int fooarray[...];")
- py.test.raises(VerificationError, ffi.verify, "char fooarray[23];")
+ pytest.raises(VerificationError, ffi.verify, "char fooarray[23];")
def test_struct_containing_struct():
ffi = FFI()
@@ -1696,7 +1696,7 @@ def test_struct_containing_struct():
def test_struct_returned_by_func():
ffi = FFI()
ffi.cdef("typedef ... foo_t; foo_t myfunc(void);")
- e = py.test.raises(TypeError, ffi.verify,
+ e = pytest.raises(TypeError, ffi.verify,
"typedef struct { int x; } foo_t; "
"foo_t myfunc(void) { foo_t x = { 42 }; return x; }")
assert str(e.value) == (
@@ -1780,7 +1780,7 @@ def test_enum_bug118():
continue # enums may always be signed with MSVC
ffi = FFI()
ffi.cdef("enum foo_e { AA=%s };" % c1)
- e = py.test.raises(VerificationError, ffi.verify,
+ e = pytest.raises(VerificationError, ffi.verify,
"enum foo_e { AA=%s%s };" % (c2, c2c))
assert str(e.value) == ('enum foo_e: AA has the real value %d, not %d'
% (c2, c1))
@@ -1885,15 +1885,15 @@ def test_passing_string_or_NULL():
assert lib.seeme1(ffi.NULL) == 1
assert lib.seeme2([42, 43]) == 0
assert lib.seeme2(ffi.NULL) == 1
- py.test.raises(TypeError, lib.seeme1, None)
- py.test.raises(TypeError, lib.seeme2, None)
- py.test.raises(TypeError, lib.seeme1, 0.0)
- py.test.raises(TypeError, lib.seeme2, 0.0)
- py.test.raises(TypeError, lib.seeme1, 0)
- py.test.raises(TypeError, lib.seeme2, 0)
+ pytest.raises(TypeError, lib.seeme1, None)
+ pytest.raises(TypeError, lib.seeme2, None)
+ pytest.raises(TypeError, lib.seeme1, 0.0)
+ pytest.raises(TypeError, lib.seeme2, 0.0)
+ pytest.raises(TypeError, lib.seeme1, 0)
+ pytest.raises(TypeError, lib.seeme2, 0)
zeroL = 99999999999999999999
zeroL -= 99999999999999999999
- py.test.raises(TypeError, lib.seeme2, zeroL)
+ pytest.raises(TypeError, lib.seeme2, zeroL)
def test_typeof_function():
ffi = FFI()
@@ -2120,7 +2120,7 @@ def test_errno_working_even_with_pypys_jit():
def test_getlasterror_working_even_with_pypys_jit():
if sys.platform != 'win32':
- py.test.skip("win32-only test")
+ pytest.skip("win32-only test")
ffi = FFI()
ffi.cdef("void SetLastError(DWORD);")
lib = ffi.dlopen("Kernel32.dll")
@@ -2167,19 +2167,19 @@ def test_consider_not_implemented_function_type():
bazptr = ffi.cast("bazfunc_t", 123)
barptr = ffi.cast("barfunc_t", 123)
# assert did not crash so far
- e = py.test.raises(NotImplementedError, fooptr, ffi.new("Data *"))
+ e = pytest.raises(NotImplementedError, fooptr, ffi.new("Data *"))
assert str(e.value) == (
"ctype 'Data' not supported as argument by libffi. Unions are only "
"supported as argument if the function is 'API mode' and "
"non-variadic (i.e. declared inside ffibuilder.cdef()+"
"ffibuilder.set_source() and not taking a final '...' argument)")
- e = py.test.raises(NotImplementedError, bazptr)
+ e = pytest.raises(NotImplementedError, bazptr)
assert str(e.value) == (
"ctype 'Data' not supported as return value by libffi. Unions are "
"only supported as return value if the function is 'API mode' and "
"non-variadic (i.e. declared inside ffibuilder.cdef()+"
"ffibuilder.set_source() and not taking a final '...' argument)")
- e = py.test.raises(NotImplementedError, barptr)
+ e = pytest.raises(NotImplementedError, barptr)
assert str(e.value) == (
"ctype 'MyStr' not supported as return value. It is a struct with "
"bit fields, which libffi does not support. Such structs are only "
@@ -2195,9 +2195,9 @@ def test_verify_extra_arguments():
def test_implicit_unicode_on_windows():
if sys.platform != 'win32':
- py.test.skip("win32-only test")
+ pytest.skip("win32-only test")
ffi = FFI()
- e = py.test.raises(FFIError, ffi.cdef, "int foo(LPTSTR);")
+ e = pytest.raises(FFIError, ffi.cdef, "int foo(LPTSTR);")
assert str(e.value) == ("The Windows type 'LPTSTR' is only available after"
" you call ffi.set_unicode()")
for with_unicode in [True, False]:
@@ -2235,7 +2235,7 @@ def test_define_known_value():
def test_define_wrong_value():
ffi = FFI()
ffi.cdef("#define FOO 123")
- e = py.test.raises(VerificationError, ffi.verify, "#define FOO 124")
+ e = pytest.raises(VerificationError, ffi.verify, "#define FOO 124")
assert str(e.value).endswith("FOO has the real value 124, not 123")
def test_static_const_int_known_value():
@@ -2247,7 +2247,7 @@ def test_static_const_int_known_value():
def test_static_const_int_wrong_value():
ffi = FFI()
ffi.cdef("static const int FOO = 123;")
- e = py.test.raises(VerificationError, ffi.verify, "#define FOO 124")
+ e = pytest.raises(VerificationError, ffi.verify, "#define FOO 124")
assert str(e.value).endswith("FOO has the real value 124, not 123")
def test_const_struct_global():
@@ -2261,12 +2261,12 @@ def test_const_struct_global():
def test_dont_support_int_dotdotdot():
ffi = FFI()
ffi.cdef("typedef int... t1;")
- e = py.test.raises(VerificationError, ffi.verify, "")
+ e = pytest.raises(VerificationError, ffi.verify, "")
assert str(e.value) == ("feature not supported with ffi.verify(), but only "
"with ffi.set_source(): 'typedef int... t1'")
ffi = FFI()
ffi.cdef("typedef double ... t1;")
- e = py.test.raises(VerificationError, ffi.verify, "")
+ e = pytest.raises(VerificationError, ffi.verify, "")
assert str(e.value) == ("feature not supported with ffi.verify(), but only "
"with ffi.set_source(): 'typedef float... t1'")
@@ -2326,8 +2326,8 @@ def test_win32_calling_convention_0():
if sys.platform == 'win32' and sys.maxsize < 2**32:
assert '__stdcall' in str(ffi.typeof(cb2))
assert '__stdcall' not in str(ffi.typeof(cb1))
- py.test.raises(TypeError, lib.call1, cb2)
- py.test.raises(TypeError, lib.call2, cb1)
+ pytest.raises(TypeError, lib.call1, cb2)
+ pytest.raises(TypeError, lib.call2, cb1)
else:
assert '__stdcall' not in str(ffi.typeof(cb2))
assert ffi.typeof(cb2) is ffi.typeof(cb1)
@@ -2450,8 +2450,8 @@ def test_win32_calling_convention_3():
}
""")
if sys.platform == 'win32' and sys.maxsize < 2**32:
- py.test.raises(TypeError, lib.call1, lib.cb2)
- py.test.raises(TypeError, lib.call2, lib.cb1)
+ pytest.raises(TypeError, lib.call1, lib.cb2)
+ pytest.raises(TypeError, lib.call2, lib.cb1)
pt = lib.call1(lib.cb1)
assert (pt.x, pt.y) == (-9*500*999, 9*500*999)
pt = lib.call2(lib.cb2)
@@ -2459,11 +2459,11 @@ def test_win32_calling_convention_3():
def _only_test_on_linux_intel():
if not sys.platform.startswith('linux'):
- py.test.skip('only running the memory-intensive test on Linux')
+ pytest.skip('only running the memory-intensive test on Linux')
import platform
machine = platform.machine()
if 'x86' not in machine and 'x64' not in machine:
- py.test.skip('only running the memory-intensive test on x86/x64')
+ pytest.skip('only running the memory-intensive test on x86/x64')
def test_ffi_gc_size_arg():
# with PyPy's GC, these calls to ffi.gc() would rapidly consume
@@ -2487,7 +2487,7 @@ def test_ffi_gc_size_arg_2():
# and I found no obvious way to prevent that. So for now, this test
# is skipped on CPython, where it eats all the memory.
if '__pypy__' not in sys.builtin_module_names:
- py.test.skip("find a way to tweak the cyclic GC of CPython")
+ pytest.skip("find a way to tweak the cyclic GC of CPython")
_only_test_on_linux_intel()
ffi = FFI()
ffi.cdef("void *malloc(size_t); void free(void *);")
@@ -2510,7 +2510,7 @@ def test_ffi_gc_size_arg_2():
def test_ffi_new_with_cycles():
# still another variant, with ffi.new()
if '__pypy__' not in sys.builtin_module_names:
- py.test.skip("find a way to tweak the cyclic GC of CPython")
+ pytest.skip("find a way to tweak the cyclic GC of CPython")
ffi = FFI()
ffi.cdef("")
lib = ffi.verify("")
diff --git a/testing/cffi0/test_version.py b/testing/cffi0/test_version.py
index facb84c..dfce94f 100644
--- a/testing/cffi0/test_version.py
+++ b/testing/cffi0/test_version.py
@@ -1,9 +1,10 @@
-import py, os, sys
+import os, sys
+import pytest
import cffi, _cffi_backend
def setup_module(mod):
if '_cffi_backend' in sys.builtin_module_names:
- py.test.skip("this is embedded version")
+ pytest.skip("this is embedded version")
#BACKEND_VERSIONS = {
# '0.4.2': '0.4', # did not change
diff --git a/testing/cffi0/test_zdistutils.py b/testing/cffi0/test_zdistutils.py
index 35b3d0c..6f46fa8 100644
--- a/testing/cffi0/test_zdistutils.py
+++ b/testing/cffi0/test_zdistutils.py
@@ -1,5 +1,5 @@
import sys, os, imp, math, shutil
-import py
+import pytest
from cffi import FFI, FFIError
from cffi.verifier import Verifier, _locate_engine_class, _get_so_suffixes
from cffi.ffiplatform import maybe_relative_path
@@ -204,7 +204,7 @@ class DistUtilsTest(object):
def test_install_and_reload_module(self, targetpackage='', ext_package=''):
KEY = repr(self)
if not hasattr(os, 'fork'):
- py.test.skip("test requires os.fork()")
+ pytest.skip("test requires os.fork()")
if targetpackage:
udir.ensure(targetpackage, dir=1).ensure('__init__.py')
diff --git a/testing/cffi0/test_zintegration.py b/testing/cffi0/test_zintegration.py
index ce925b8..d6a02ce 100644
--- a/testing/cffi0/test_zintegration.py
+++ b/testing/cffi0/test_zintegration.py
@@ -19,7 +19,7 @@ def create_venv(name):
'-p', os.path.abspath(sys.executable),
str(tmpdir)])
except OSError as e:
- py.test.skip("Cannot execute virtualenv: %s" % (e,))
+ pytest.skip("Cannot execute virtualenv: %s" % (e,))
site_packages = None
for dirpath, dirnames, filenames in os.walk(str(tmpdir)):
@@ -159,7 +159,7 @@ class TestZIntegration(object):
try:
import setuptools
except ImportError as e:
- py.test.skip(str(e))
+ pytest.skip(str(e))
orig_version = setuptools.__version__
expecting_limited_api = not hasattr(sys, 'gettotalrefcount')
try: