diff options
Diffstat (limited to 'testing/cffi1')
-rw-r--r-- | testing/cffi1/test_cffi_binary.py | 7 | ||||
-rw-r--r-- | testing/cffi1/test_commontypes.py | 5 | ||||
-rw-r--r-- | testing/cffi1/test_dlopen.py | 10 | ||||
-rw-r--r-- | testing/cffi1/test_ffi_obj.py | 48 | ||||
-rw-r--r-- | testing/cffi1/test_new_ffi_1.py | 131 | ||||
-rw-r--r-- | testing/cffi1/test_parse_c_type.py | 9 | ||||
-rw-r--r-- | testing/cffi1/test_pkgconfig.py | 10 | ||||
-rw-r--r-- | testing/cffi1/test_re_python.py | 22 | ||||
-rw-r--r-- | testing/cffi1/test_realize_c_type.py | 5 | ||||
-rw-r--r-- | testing/cffi1/test_recompiler.py | 166 | ||||
-rw-r--r-- | testing/cffi1/test_verify1.py | 184 | ||||
-rw-r--r-- | testing/cffi1/test_zdist.py | 9 |
12 files changed, 305 insertions, 301 deletions
diff --git a/testing/cffi1/test_cffi_binary.py b/testing/cffi1/test_cffi_binary.py index 45421ed..2fb042c 100644 --- a/testing/cffi1/test_cffi_binary.py +++ b/testing/cffi1/test_cffi_binary.py @@ -1,12 +1,13 @@ -import py, sys, os +import sys, os +import pytest import _cffi_backend from testing.support import is_musl def test_no_unknown_exported_symbols(): if not hasattr(_cffi_backend, '__file__'): - py.test.skip("_cffi_backend module is built-in") + pytest.skip("_cffi_backend module is built-in") if not sys.platform.startswith('linux') or is_musl: - py.test.skip("linux-only") + pytest.skip("linux-only") g = os.popen("objdump -T '%s'" % _cffi_backend.__file__, 'r') for line in g: if not line.startswith('0'): diff --git a/testing/cffi1/test_commontypes.py b/testing/cffi1/test_commontypes.py index ea7ffde..9e7d79e 100644 --- a/testing/cffi1/test_commontypes.py +++ b/testing/cffi1/test_commontypes.py @@ -1,4 +1,5 @@ -import py, os, cffi, re +import os, cffi, re +import pytest import _cffi_backend @@ -7,7 +8,7 @@ def getlines(): f = open(os.path.join(os.path.dirname(cffi.__file__), '..', 'c', 'commontypes.c')) except IOError: - py.test.skip("cannot find ../c/commontypes.c") + pytest.skip("cannot find ../c/commontypes.c") lines = [line for line in f.readlines() if line.strip().startswith('EQ(')] f.close() return lines diff --git a/testing/cffi1/test_dlopen.py b/testing/cffi1/test_dlopen.py index 26a2717..11681d2 100644 --- a/testing/cffi1/test_dlopen.py +++ b/testing/cffi1/test_dlopen.py @@ -1,4 +1,4 @@ -import py +import pytest from cffi import FFI, VerificationError, CDefError from cffi.recompiler import make_py_source from testing.udir import udir @@ -36,7 +36,7 @@ ffi = _cffi_backend.FFI('test_valid_global_constant', def test_invalid_global_constant_3(): ffi = FFI() - e = py.test.raises(CDefError, ffi.cdef, "#define BB 12.34") + e = pytest.raises(CDefError, ffi.cdef, "#define BB 12.34") assert str(e.value).startswith( "only supports one of the following syntax:") @@ -44,7 +44,7 @@ def test_invalid_dotdotdot_in_macro(): ffi = FFI() ffi.cdef("#define FOO ...") target = udir.join('test_invalid_dotdotdot_in_macro.py') - e = py.test.raises(VerificationError, make_py_source, ffi, + e = pytest.raises(VerificationError, make_py_source, ffi, 'test_invalid_dotdotdot_in_macro', str(target)) assert str(e.value) == ("macro FOO: cannot use the syntax '...' in " "'#define FOO ...' when using the ABI mode") @@ -169,7 +169,7 @@ def test_no_cross_include(): ffi = FFI() ffi.include(baseffi) target = udir.join('test_no_cross_include.py') - py.test.raises(VerificationError, make_py_source, + pytest.raises(VerificationError, make_py_source, ffi, 'test_no_cross_include', str(target)) def test_array(): @@ -191,7 +191,7 @@ def test_array_overflow(): ffi = FFI() ffi.cdef("typedef int32_t my_array_t[3000000000];") target = udir.join('test_array_overflow.py') - py.test.raises(OverflowError, make_py_source, + pytest.raises(OverflowError, make_py_source, ffi, 'test_array_overflow', str(target)) def test_global_var(): diff --git a/testing/cffi1/test_ffi_obj.py b/testing/cffi1/test_ffi_obj.py index 0d29290..9085fb8 100644 --- a/testing/cffi1/test_ffi_obj.py +++ b/testing/cffi1/test_ffi_obj.py @@ -1,4 +1,4 @@ -import py, sys +import sys import pytest import _cffi_backend as _cffi1_backend @@ -21,7 +21,7 @@ def test_ffi_subclass(): assert type(foo) is foo.__class__ is FOO def test_ffi_no_argument(): - py.test.raises(TypeError, _cffi1_backend.FFI, 42) + pytest.raises(TypeError, _cffi1_backend.FFI, 42) def test_ffi_cache_type(): ffi = _cffi1_backend.FFI() @@ -68,7 +68,7 @@ def test_ffi_cache_type_globally(): def test_ffi_invalid(): ffi = _cffi1_backend.FFI() # array of 10 times an "int[]" is invalid - py.test.raises(ValueError, ffi.typeof, "int[10][]") + pytest.raises(ValueError, ffi.typeof, "int[10][]") def test_ffi_docstrings(): # check that all methods of the FFI class have a docstring. @@ -117,7 +117,7 @@ def test_ffi_alignof(): def test_ffi_sizeof(): ffi = _cffi1_backend.FFI() assert ffi.sizeof("int") == 4 - py.test.raises(ffi.error, ffi.sizeof, "int[]") + pytest.raises(ffi.error, ffi.sizeof, "int[]") assert ffi.sizeof("int[41]") == 41 * 4 assert ffi.sizeof(ffi.new("int[41]")) == 41 * 4 assert ffi.sizeof(ffi.new("int[]", 41)) == 41 * 4 @@ -162,7 +162,7 @@ def test_ffi_callback_onerror(): assert isinstance(val, TypeError) assert tb.tb_frame.f_code.co_name == "fn2" # - py.test.raises(TypeError, ffi.callback, "int(int)", + pytest.raises(TypeError, ffi.callback, "int(int)", lambda x: x, onerror=42) # <- not callable def test_ffi_getctype(): @@ -208,28 +208,28 @@ def test_ffi_cast(): ffi = _cffi1_backend.FFI() assert ffi.cast("int(*)(int)", 0) == ffi.NULL ffi.callback("int(int)") # side-effect of registering this string - py.test.raises(ffi.error, ffi.cast, "int(int)", 0) + pytest.raises(ffi.error, ffi.cast, "int(int)", 0) def test_ffi_invalid_type(): ffi = _cffi1_backend.FFI() - e = py.test.raises(ffi.error, ffi.cast, "", 0) + e = pytest.raises(ffi.error, ffi.cast, "", 0) assert str(e.value) == ("identifier expected\n" "\n" "^") - e = py.test.raises(ffi.error, ffi.cast, "struct struct", 0) + e = pytest.raises(ffi.error, ffi.cast, "struct struct", 0) assert str(e.value) == ("struct or union name expected\n" "struct struct\n" " ^") - e = py.test.raises(ffi.error, ffi.cast, "struct never_heard_of_s", 0) + e = pytest.raises(ffi.error, ffi.cast, "struct never_heard_of_s", 0) assert str(e.value) == ("undefined struct/union name\n" "struct never_heard_of_s\n" " ^") - e = py.test.raises(ffi.error, ffi.cast, "\t\n\x01\x1f~\x7f\x80\xff", 0) + e = pytest.raises(ffi.error, ffi.cast, "\t\n\x01\x1f~\x7f\x80\xff", 0) marks = "?" if sys.version_info < (3,) else "??" assert str(e.value) == ("identifier expected\n" " ??~?%s%s\n" " ^" % (marks, marks)) - e = py.test.raises(ffi.error, ffi.cast, "X" * 600, 0) + e = pytest.raises(ffi.error, ffi.cast, "X" * 600, 0) assert str(e.value) == ("undefined type name") def test_ffi_buffer(): @@ -248,7 +248,7 @@ def test_ffi_from_buffer(): assert len(c) == 8 ffi.cast("unsigned short *", c)[1] += 500 assert list(a) == [10000, 20500, 30000, 40000] - py.test.raises(TypeError, ffi.from_buffer, a, True) + pytest.raises(TypeError, ffi.from_buffer, a, True) assert c == ffi.from_buffer("char[]", a, True) assert c == ffi.from_buffer(a, require_writable=True) # @@ -265,9 +265,9 @@ def test_ffi_from_buffer(): 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_memmove(): @@ -318,7 +318,7 @@ def test_memmove_readonly_readwrite(): 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") @@ -332,7 +332,7 @@ def test_ffi_types(): def test_ffi_getwinerror(): if sys.platform != "win32": - py.test.skip("for windows") + pytest.skip("for windows") ffi = _cffi1_backend.FFI() n = (1 << 29) + 42 code, message = ffi.getwinerror(code=n) @@ -407,29 +407,29 @@ def test_ffi_new_allocator_3(): def test_ffi_new_allocator_4(): ffi = _cffi1_backend.FFI() - 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_bool_issue228(): ffi = _cffi1_backend.FFI() @@ -497,7 +497,7 @@ def test_init_once_failure(): ffi = _cffi1_backend.FFI() seen = [] for i in range(5): - py.test.raises(ValueError, ffi.init_once, do_init, "tag") + pytest.raises(ValueError, ffi.init_once, do_init, "tag") assert seen == [1] * (i + 1) def test_init_once_multithread_failure(): @@ -515,7 +515,7 @@ def test_init_once_multithread_failure(): seen = [] for i in range(3): def f(): - py.test.raises(ValueError, ffi.init_once, do_init, "tag") + pytest.raises(ValueError, ffi.init_once, do_init, "tag") thread.start_new_thread(f, ()) i = 0 while len(seen) < 6: @@ -533,4 +533,4 @@ def test_unpack(): def test_negative_array_size(): ffi = _cffi1_backend.FFI() - py.test.raises(ffi.error, ffi.cast, "int[-5]", 0) + pytest.raises(ffi.error, ffi.cast, "int[-5]", 0) diff --git a/testing/cffi1/test_new_ffi_1.py b/testing/cffi1/test_new_ffi_1.py index 640830b..c874a36 100644 --- a/testing/cffi1/test_new_ffi_1.py +++ b/testing/cffi1/test_new_ffi_1.py @@ -1,4 +1,3 @@ -import py import pytest import platform, imp import sys, os, ctypes @@ -153,17 +152,17 @@ class TestNewFFI1: 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 assert ffi.new(c_decl_ptr, long(max))[0] == max def test_new_unsupported_type(self): - 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): @@ -220,7 +219,7 @@ class TestNewFFI1: 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 @@ -232,7 +231,7 @@ class TestNewFFI1: 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): @@ -245,7 +244,7 @@ class TestNewFFI1: def test_cannot_cast(self): 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 @@ -362,9 +361,9 @@ class TestNewFFI1: 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 @@ -383,13 +382,13 @@ class TestNewFFI1: 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): self.check_wchar_t(ffi) @@ -398,7 +397,7 @@ class TestNewFFI1: 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)) @@ -406,8 +405,8 @@ class TestNewFFI1: 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 @@ -442,7 +441,7 @@ class TestNewFFI1: 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): p = ffi.new("int*[1]") @@ -468,8 +467,8 @@ class TestNewFFI1: # 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 # @@ -500,14 +499,14 @@ class TestNewFFI1: assert repr(s) == "<cdata 'struct simple *' owning %d bytes>" % ( SIZE_OF_INT + 2 * SIZE_OF_SHORT) # - py.test.raises(ValueError, ffi.new, "struct simple*", [1, 2, 3, 4]) + pytest.raises(ValueError, ffi.new, "struct simple*", [1, 2, 3, 4]) def test_constructor_struct_from_dict(self): s = ffi.new("struct simple*", {'b': 123, 'c': 456}) assert s.a == 0 assert s.b == 123 assert s.c == 456 - py.test.raises(KeyError, ffi.new, "struct simple*", {'d': 456}) + pytest.raises(KeyError, ffi.new, "struct simple*", {'d': 456}) def test_struct_pointer(self): s = ffi.new("struct simple*") @@ -520,10 +519,10 @@ class TestNewFFI1: s[1] def test_struct_opaque(self): - py.test.raises(ffi.error, ffi.new, "struct baz*") + pytest.raises(ffi.error, ffi.new, "struct baz*") # should 'ffi.new("struct baz **") work? it used to, but it was # not particularly useful... - py.test.raises(ffi.error, ffi.new, "struct baz**") + pytest.raises(ffi.error, ffi.new, "struct baz**") def test_pointer_to_struct(self): s = ffi.new("struct simple *") @@ -580,18 +579,18 @@ class TestNewFFI1: SIZE_OF_INT,) def test_union_opaque(self): - py.test.raises(ffi.error, ffi.new, "union baz*") + pytest.raises(ffi.error, ffi.new, "union baz*") # should 'ffi.new("union baz **") work? it used to, but it was # not particularly useful... - py.test.raises(ffi.error, ffi.new, "union baz**") + pytest.raises(ffi.error, ffi.new, "union baz**") def test_union_initializer(self): - py.test.raises(TypeError, ffi.new, "union init_u*", b'A') - py.test.raises(TypeError, ffi.new, "union init_u*", 5) - py.test.raises(ValueError, ffi.new, "union init_u*", [b'A', 5]) + pytest.raises(TypeError, ffi.new, "union init_u*", b'A') + pytest.raises(TypeError, ffi.new, "union init_u*", 5) + pytest.raises(ValueError, ffi.new, "union init_u*", [b'A', 5]) u = ffi.new("union init_u*", [b'A']) assert u.a == b'A' - py.test.raises(TypeError, ffi.new, "union init_u*", [1005]) + pytest.raises(TypeError, ffi.new, "union init_u*", [1005]) u = ffi.new("union init_u*", {'b': 12345}) assert u.b == 12345 u = ffi.new("union init_u*", []) @@ -623,7 +622,7 @@ class TestNewFFI1: 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): self.check_wchar_t(ffi) @@ -698,7 +697,7 @@ class TestNewFFI1: assert s.name == ffi.NULL def test_voidp(self): - 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]) @@ -706,7 +705,7 @@ class TestNewFFI1: vp = p[0] with pytest.raises(TypeError): vp[0] - py.test.raises(TypeError, ffi.new, "short **", a) + pytest.raises(TypeError, ffi.new, "short **", a) # s = ffi.new("struct voidp *") s.p = a # works @@ -720,7 +719,7 @@ class TestNewFFI1: s.r = b # fails def test_functionptr_simple(self): - 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' @@ -992,10 +991,10 @@ class TestNewFFI1: 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): # struct abc { int a, b, c; }; @@ -1006,7 +1005,7 @@ class TestNewFFI1: def test_offsetof_nested(self): # struct nesting { struct abc d, e; }; assert ffi.offsetof("struct nesting", "e") == 12 - py.test.raises(KeyError, ffi.offsetof, "struct nesting", "e.a") + pytest.raises(KeyError, ffi.offsetof, "struct nesting", "e.a") assert ffi.offsetof("struct nesting", "e", "a") == 12 assert ffi.offsetof("struct nesting", "e", "b") == 16 assert ffi.offsetof("struct nesting", "e", "c") == 20 @@ -1054,7 +1053,7 @@ class TestNewFFI1: # typedef enum { AA1, BB1, CC1 } foo_e_t; # typedef struct { foo_e_t f:2; } bfenum_t; if sys.platform == "win32": - py.test.skip("enums are not unsigned") + pytest.skip("enums are not unsigned") s = ffi.new("bfenum_t *") s.f = 2 assert s.f == 2 @@ -1154,7 +1153,7 @@ class TestNewFFI1: try: b = ffi.buffer(a) except NotImplementedError as e: - py.test.skip(str(e)) + pytest.skip(str(e)) content = b[:] assert len(content) == len(b) == 2 if sys.byteorder == 'little': @@ -1172,7 +1171,7 @@ class TestNewFFI1: 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') @@ -1188,7 +1187,7 @@ class TestNewFFI1: 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': @@ -1206,7 +1205,7 @@ class TestNewFFI1: 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): @@ -1217,7 +1216,7 @@ class TestNewFFI1: 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))) @@ -1235,7 +1234,7 @@ class TestNewFFI1: 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))) @@ -1254,7 +1253,7 @@ class TestNewFFI1: def test_struct_containing_array_varsize_workaround(self): if sys.platform == "win32": - py.test.skip("array of length 0 not supported") + pytest.skip("array of length 0 not supported") # struct array0 { int len; short data[0]; }; p = ffi.new("char[]", ffi.sizeof("struct array0") + 7 * SIZE_OF_SHORT) q = ffi.cast("struct array0 *", p) @@ -1266,7 +1265,7 @@ class TestNewFFI1: assert q.data[6] == 15 def test_new_struct_containing_array_varsize(self): - py.test.skip("later?") + pytest.skip("later?") ffi.cdef("struct foo_s { int len; short data[]; };") p = ffi.new("struct foo_s *", 10) # a single integer is the length assert p.len == 0 @@ -1294,14 +1293,14 @@ class TestNewFFI1: def test_array_of_func_ptr(self): f = ffi.cast("int(*)(int)", 42) assert f != ffi.NULL - py.test.raises(ffi.error, ffi.cast, "int(int)", 42) - py.test.raises(ffi.error, ffi.new, "int([5])(int)") + pytest.raises(ffi.error, ffi.cast, "int(int)", 42) + pytest.raises(ffi.error, 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 @@ -1322,7 +1321,7 @@ class TestNewFFI1: assert g(f) == b'B' def test_vararg_callback(self): - py.test.skip("callback with '...'") + pytest.skip("callback with '...'") def cb(i, va_list): j = ffi.va_arg(va_list, "int") k = ffi.va_arg(va_list, "long long") @@ -1349,7 +1348,7 @@ class TestNewFFI1: def test_new_ctype(self): 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 @@ -1540,17 +1539,17 @@ class TestNewFFI1: 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_addressof(self): p = ffi.new("struct ab *") a = ffi.addressof(p[0]) assert repr(a).startswith("<cdata 'struct ab *' 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): p = ffi.new("struct ab *") @@ -1564,7 +1563,7 @@ class TestNewFFI1: def test_addressof_field_nested(self): # struct nesting { struct abc d, e; }; p = ffi.new("struct nesting *") - py.test.raises(KeyError, ffi.addressof, p[0], 'e.b') + pytest.raises(KeyError, ffi.addressof, p[0], 'e.b') a = ffi.addressof(p[0], 'e', 'b') assert int(ffi.cast("uintptr_t", a)) == ( int(ffi.cast("uintptr_t", p)) + @@ -1581,7 +1580,7 @@ class TestNewFFI1: 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 *") @@ -1591,14 +1590,14 @@ class TestNewFFI1: def test_addressof_pointer(self): 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) # array = ffi.new("struct ab[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) @@ -1675,7 +1674,7 @@ class TestNewFFI1: def test_not_supported_bitfield_in_result(self): # struct ints_and_bitfield { int a,b,c,d,e; int x:1; }; - e = py.test.raises(NotImplementedError, ffi.callback, + e = pytest.raises(NotImplementedError, ffi.callback, "struct ints_and_bitfield foo(void)", lambda: 42) assert str(e.value) == ("struct ints_and_bitfield(*)(): " "callback with unsupported argument or return type or with '...'") @@ -1692,7 +1691,7 @@ class TestNewFFI1: 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_struct_array_no_length(self): # struct array_no_length { int x; int a[]; }; @@ -1709,8 +1708,8 @@ class TestNewFFI1: assert q.a[0] == 200 assert q.a[1] == 300 assert q.a[2] == 400 - py.test.raises(TypeError, len, q.a) - py.test.raises(TypeError, list, q.a) + pytest.raises(TypeError, len, q.a) + pytest.raises(TypeError, list, q.a) def test_all_primitives(self): assert set(PRIMITIVE_TO_INDEX) == set([ diff --git a/testing/cffi1/test_parse_c_type.py b/testing/cffi1/test_parse_c_type.py index a9f5fcb..fa1f36c 100644 --- a/testing/cffi1/test_parse_c_type.py +++ b/testing/cffi1/test_parse_c_type.py @@ -1,14 +1,15 @@ -import sys, re, os, py +import sys, re, os +import pytest import cffi from cffi import cffi_opcode if '__pypy__' in sys.builtin_module_names: try: # pytest >= 4.0 - py.test.skip("not available on pypy", allow_module_level=True) + pytest.skip("not available on pypy", allow_module_level=True) except TypeError: # older pytest - py.test.skip("not available on pypy") + pytest.skip("not available on pypy") cffi_dir = os.path.dirname(cffi_opcode.__file__) @@ -130,7 +131,7 @@ def parsex(input): return ' '.join(map(str_if_int, result)) def parse_error(input, expected_msg, expected_location): - e = py.test.raises(ParseError, parse, input) + e = pytest.raises(ParseError, parse, input) assert e.value.args[0] == expected_msg assert e.value.args[1] == expected_location diff --git a/testing/cffi1/test_pkgconfig.py b/testing/cffi1/test_pkgconfig.py index c725cca..40e0059 100644 --- a/testing/cffi1/test_pkgconfig.py +++ b/testing/cffi1/test_pkgconfig.py @@ -1,6 +1,6 @@ import sys import subprocess -import py +import pytest import cffi.pkgconfig as pkgconfig from cffi import PkgConfigError @@ -62,15 +62,15 @@ def test_call(): pkgconfig.subprocess = mock_subprocess mock_subprocess.RESULT = None - e = py.test.raises(PkgConfigError, pkgconfig.call, "libfoo", "--cflags") + e = pytest.raises(PkgConfigError, pkgconfig.call, "libfoo", "--cflags") assert str(e.value) == "cannot run pkg-config: oops can't run" mock_subprocess.RESULT = b"", "Foo error!\n", 1 - e = py.test.raises(PkgConfigError, pkgconfig.call, "libfoo", "--cflags") + e = pytest.raises(PkgConfigError, pkgconfig.call, "libfoo", "--cflags") assert str(e.value) == "Foo error!" mock_subprocess.RESULT = b"abc\\def\n", "", 0 - e = py.test.raises(PkgConfigError, pkgconfig.call, "libfoo", "--cflags") + e = pytest.raises(PkgConfigError, pkgconfig.call, "libfoo", "--cflags") assert str(e.value).startswith("pkg-config --cflags libfoo returned an " "unsupported backslash-escaped output:") @@ -84,7 +84,7 @@ def test_call(): if sys.version_info >= (3,): mock_subprocess.RESULT = b"\xff\n", "", 0 - e = py.test.raises(PkgConfigError, pkgconfig.call, + e = pytest.raises(PkgConfigError, pkgconfig.call, "libfoo", "--cflags", encoding="utf-8") assert str(e.value) == ( "pkg-config --cflags libfoo returned bytes that cannot be " diff --git a/testing/cffi1/test_re_python.py b/testing/cffi1/test_re_python.py index 45dd70c..fdf083a 100644 --- a/testing/cffi1/test_re_python.py +++ b/testing/cffi1/test_re_python.py @@ -1,5 +1,5 @@ import sys, os -import py +import pytest from cffi import FFI from cffi import recompiler, ffiplatform, VerificationMissing from testing.udir import udir @@ -117,7 +117,7 @@ def test_dlopen_none(): import ctypes.util name = ctypes.util.find_msvcrt() if name is None: - py.test.skip("dlopen(None) cannot work on Windows with Python 3") + pytest.skip("dlopen(None) cannot work on Windows with Python 3") lib = ffi.dlopen(name) assert lib.strlen(b"hello") == 5 @@ -130,7 +130,7 @@ def test_dlclose(): str_extmod = extmod.encode('utf-8') else: str_extmod = extmod - e = py.test.raises(ffi.error, getattr, lib, 'add42') + e = pytest.raises(ffi.error, getattr, lib, 'add42') assert str(e.value) == ( "library '%s' has been closed" % (str_extmod,)) ffi.dlclose(lib) # does not raise @@ -144,7 +144,7 @@ def test_constant_via_lib(): def test_opaque_struct(): from re_python_pysrc import ffi ffi.cast("struct foo_s *", 0) - py.test.raises(TypeError, ffi.new, "struct foo_s *") + pytest.raises(TypeError, ffi.new, "struct foo_s *") def test_nonopaque_struct(): from re_python_pysrc import ffi @@ -199,13 +199,13 @@ def test_global_const_int(): from re_python_pysrc import ffi lib = ffi.dlopen(extmod) assert lib.globalconst42 == 4321 - py.test.raises(AttributeError, ffi.addressof, lib, 'globalconst42') + pytest.raises(AttributeError, ffi.addressof, lib, 'globalconst42') def test_global_const_nonint(): from re_python_pysrc import ffi lib = ffi.dlopen(extmod) assert ffi.string(lib.globalconsthello, 8) == b"hello" - py.test.raises(AttributeError, ffi.addressof, lib, 'globalconsthello') + pytest.raises(AttributeError, ffi.addressof, lib, 'globalconsthello') def test_rtld_constants(): from re_python_pysrc import ffi @@ -216,16 +216,16 @@ def test_rtld_constants(): def test_no_such_function_or_global_var(): from re_python_pysrc import ffi lib = ffi.dlopen(extmod) - e = py.test.raises(ffi.error, getattr, lib, 'no_such_function') + e = pytest.raises(ffi.error, getattr, lib, 'no_such_function') assert str(e.value).startswith( "symbol 'no_such_function' not found in library '") - e = py.test.raises(ffi.error, getattr, lib, 'no_such_globalvar') + e = pytest.raises(ffi.error, getattr, lib, 'no_such_globalvar') assert str(e.value).startswith( "symbol 'no_such_globalvar' not found in library '") def test_check_version(): import _cffi_backend - e = py.test.raises(ImportError, _cffi_backend.FFI, + e = pytest.raises(ImportError, _cffi_backend.FFI, "foobar", _version=0x2594) assert str(e.value).startswith( "cffi out-of-line Python module 'foobar' has unknown version") @@ -234,7 +234,7 @@ def test_partial_enum(): ffi = FFI() ffi.cdef("enum foo { A, B, ... };") ffi.set_source('test_partial_enum', None) - py.test.raises(VerificationMissing, ffi.emit_python_code, + pytest.raises(VerificationMissing, ffi.emit_python_code, str(tmpdir.join('test_partial_enum.py'))) def test_anonymous_union_inside_struct(): @@ -270,7 +270,7 @@ def test_dlopen_handle(): import _cffi_backend from re_python_pysrc import ffi if sys.platform == 'win32' or is_musl: - py.test.skip("uses 'dl' explicitly") + pytest.skip("uses 'dl' explicitly") ffi1 = FFI() ffi1.cdef("""void *dlopen(const char *filename, int flags); int dlclose(void *handle);""") diff --git a/testing/cffi1/test_realize_c_type.py b/testing/cffi1/test_realize_c_type.py index a1f31e6..824beaf 100644 --- a/testing/cffi1/test_realize_c_type.py +++ b/testing/cffi1/test_realize_c_type.py @@ -1,4 +1,5 @@ -import py, sys +import sys +import pytest from cffi import cffi_opcode @@ -10,7 +11,7 @@ def check(input, expected_output=None, expected_ffi_error=False): assert isinstance(ct, ffi.CType) assert ct.cname == (expected_output or input) else: - e = py.test.raises(ffi.error, ffi.typeof, input) + e = pytest.raises(ffi.error, ffi.typeof, input) if isinstance(expected_ffi_error, str): assert str(e.value) == expected_ffi_error diff --git a/testing/cffi1/test_recompiler.py b/testing/cffi1/test_recompiler.py index fdb4d5a..362a372 100644 --- a/testing/cffi1/test_recompiler.py +++ b/testing/cffi1/test_recompiler.py @@ -1,5 +1,5 @@ -import sys, os, py +import sys, os import pytest from cffi import FFI, VerificationError, FFIError, CDefError from cffi import recompiler @@ -45,8 +45,8 @@ def verify(ffi, module_name, source, *args, **kwds): def test_set_source_no_slashes(): ffi = FFI() - py.test.raises(ValueError, ffi.set_source, "abc/def", None) - py.test.raises(ValueError, ffi.set_source, "abc/def", "C code") + pytest.raises(ValueError, ffi.set_source, "abc/def", None) + pytest.raises(ValueError, ffi.set_source, "abc/def", "C code") def test_type_table_func(): @@ -250,7 +250,7 @@ def test_macro_check_value(): x = getattr(lib, attrname) assert x == c_got else: - e = py.test.raises(ffi.error, getattr, lib, attrname) + e = pytest.raises(ffi.error, getattr, lib, attrname) assert str(e.value) == ( "the C compiler says '%s' is equal to " "%s, but the cdef disagrees" % (attrname, c_compiler_msg)) @@ -268,7 +268,7 @@ def test_check_value_of_static_const(): ffi.cdef("static const int FOOBAR = 042;") lib = verify(ffi, 'test_check_value_of_static_const', "#define FOOBAR (-6912)") - e = py.test.raises(ffi.error, getattr, lib, 'FOOBAR') + e = pytest.raises(ffi.error, getattr, lib, 'FOOBAR') assert str(e.value) == ( "the C compiler says 'FOOBAR' is equal to -6912, but the cdef disagrees") @@ -341,7 +341,7 @@ def test_verify_struct(): assert ffi.offsetof("struct foo_s", "b") == 4 assert ffi.offsetof(u+"struct foo_s", u+"b") == 4 # - py.test.raises(TypeError, ffi.addressof, p) + pytest.raises(TypeError, ffi.addressof, p) assert ffi.addressof(p[0]) == p assert ffi.typeof(ffi.addressof(p[0])) is ffi.typeof("struct foo_s *") assert ffi.typeof(ffi.addressof(p, "b")) is ffi.typeof("int *") @@ -352,7 +352,7 @@ def test_verify_exact_field_offset(): ffi.cdef("""struct foo_s { int b; short a; };""") lib = verify(ffi, 'test_verify_exact_field_offset', """struct foo_s { short a; int b; };""") - e = py.test.raises(ffi.error, ffi.new, "struct foo_s *", []) # lazily + e = pytest.raises(ffi.error, ffi.new, "struct foo_s *", []) # lazily assert str(e.value).startswith( "struct foo_s: wrong offset for field 'b' (cdef " 'says 0, but C compiler says 4). fix it or use "...;" ') @@ -393,7 +393,7 @@ def test_verify_enum(): def test_duplicate_enum(): ffi = FFI() ffi.cdef("enum e1 { A1, ... }; enum e2 { A1, ... };") - py.test.raises(VerificationError, verify, ffi, 'test_duplicate_enum', + pytest.raises(VerificationError, verify, ffi, 'test_duplicate_enum', "enum e1 { A1 }; enum e2 { B1 };") def test_dotdotdot_length_of_array_field(): @@ -463,7 +463,7 @@ def test_math_sin_type(): assert ffi.typeof(lib.sin).cname == "double(*)(double)" # 'x' is another <built-in method> object on lib, made very indirectly x = type(lib).__dir__.__get__(lib) - py.test.raises(TypeError, ffi.typeof, x) + pytest.raises(TypeError, ffi.typeof, x) # # present on built-in functions on CPython; must be emulated on PyPy: assert lib.sin.__name__ == 'sin' @@ -567,13 +567,13 @@ def test_module_name_in_package(): def test_bad_size_of_global_1(): ffi = FFI() ffi.cdef("extern short glob;") - py.test.raises(VerificationError, verify, ffi, + pytest.raises(VerificationError, verify, ffi, "test_bad_size_of_global_1", "long glob;") def test_bad_size_of_global_2(): ffi = FFI() ffi.cdef("extern int glob[10];") - py.test.raises(VerificationError, verify, ffi, + pytest.raises(VerificationError, verify, ffi, "test_bad_size_of_global_2", "int glob[9];") def test_unspecified_size_of_global_1(): @@ -737,7 +737,7 @@ def test_include_8(): ffi.include(ffi1) ffi.cdef("struct foo_s { int x, y; };") verify(ffi, "test_include_8", "struct foo_s { int x, y; };") - e = py.test.raises(NotImplementedError, ffi.new, "struct foo_s *") + e = pytest.raises(NotImplementedError, ffi.new, "struct foo_s *") assert str(e.value) == ( "'struct foo_s' is opaque in the ffi.include(), but no longer in " "the ffi doing the include (workaround: don't use ffi.include() but" @@ -747,7 +747,7 @@ def test_unicode_libraries(): try: unicode except NameError: - py.test.skip("for python 2.x") + pytest.skip("for python 2.x") # import math lib_m = "m" @@ -848,8 +848,8 @@ def test_address_of_global_var(): assert ffi.typeof(p) == ffi.typeof("long(*)[2]") assert p[0] == lib.bottoms # - py.test.raises(AttributeError, ffi.addressof, lib, 'unknown_var') - py.test.raises(AttributeError, ffi.addressof, lib, "FOOBAR") + pytest.raises(AttributeError, ffi.addressof, lib, 'unknown_var') + pytest.raises(AttributeError, ffi.addressof, lib, "FOOBAR") def test_defines__CFFI_(): # Check that we define the macro _CFFI_ automatically. @@ -880,13 +880,13 @@ def test_unpack_args(): lib.foo0() lib.foo1(42) lib.foo2(43, 44) - e1 = py.test.raises(TypeError, lib.foo0, 42) - e2 = py.test.raises(TypeError, lib.foo0, 43, 44) - e3 = py.test.raises(TypeError, lib.foo1) - e4 = py.test.raises(TypeError, lib.foo1, 43, 44) - e5 = py.test.raises(TypeError, lib.foo2) - e6 = py.test.raises(TypeError, lib.foo2, 42) - e7 = py.test.raises(TypeError, lib.foo2, 45, 46, 47) + e1 = pytest.raises(TypeError, lib.foo0, 42) + e2 = pytest.raises(TypeError, lib.foo0, 43, 44) + e3 = pytest.raises(TypeError, lib.foo1) + e4 = pytest.raises(TypeError, lib.foo1, 43, 44) + e5 = pytest.raises(TypeError, lib.foo2) + e6 = pytest.raises(TypeError, lib.foo2, 42) + e7 = pytest.raises(TypeError, lib.foo2, 45, 46, 47) def st1(s): s = str(s) if s.startswith("_CFFI_test_unpack_args.Lib."): @@ -971,7 +971,7 @@ def test_constant_of_unknown_size(): lib = verify(ffi, 'test_constant_of_unknown_size', "typedef int opaque_t;" "const int CONSTANT = 42;") - e = py.test.raises(ffi.error, getattr, lib, 'CONSTANT') + e = pytest.raises(ffi.error, getattr, lib, 'CONSTANT') assert str(e.value) == ("constant 'CONSTANT' is of " "type 'opaque_t', whose size is not known") @@ -986,10 +986,10 @@ def test_variable_of_unknown_size(): opaque_t globvar = "hello"; """) # can't read or write it at all - e = py.test.raises(TypeError, getattr, lib, 'globvar') + e = pytest.raises(TypeError, getattr, lib, 'globvar') assert str(e.value) in ["cdata 'opaque_t' is opaque", "'opaque_t' is opaque or not completed yet"] #pypy - e = py.test.raises(TypeError, setattr, lib, 'globvar', []) + e = pytest.raises(TypeError, setattr, lib, 'globvar', []) assert str(e.value) in ["'opaque_t' is opaque", "'opaque_t' is opaque or not completed yet"] #pypy # but we can get its address @@ -1132,9 +1132,9 @@ def test_some_integer_type(): assert lib.foobar(2 ** 15 - 1, [0, 0]) == 2 ** 15 - 1 assert lib.foobar(10, [20, 31]) == 61 assert lib.foobar(0, [0, maxulonglong]) == maxulonglong - py.test.raises(OverflowError, lib.foobar, 2 ** 15, [0, 0]) - py.test.raises(OverflowError, lib.foobar, -(2 ** 15) - 1, [0, 0]) - py.test.raises(OverflowError, ffi.new, "mystruct_t *", [0, -1]) + pytest.raises(OverflowError, lib.foobar, 2 ** 15, [0, 0]) + pytest.raises(OverflowError, lib.foobar, -(2 ** 15) - 1, [0, 0]) + pytest.raises(OverflowError, ffi.new, "mystruct_t *", [0, -1]) assert lib.mu == -20 assert lib.nu == 20 @@ -1160,7 +1160,7 @@ def test_some_float_type(): def test_some_float_invalid_1(): ffi = FFI() - py.test.raises((FFIError, # with pycparser <= 2.17 + pytest.raises((FFIError, # with pycparser <= 2.17 CDefError), # with pycparser >= 2.18 ffi.cdef, "typedef long double... foo_t;") @@ -1171,7 +1171,7 @@ def test_some_float_invalid_2(): typedef unsigned long foo_t; foo_t neg(foo_t x) { return -x; } """) - e = py.test.raises(ffi.error, getattr, lib, 'neg') + e = pytest.raises(ffi.error, getattr, lib, 'neg') assert str(e.value) == ("primitive floating-point type with an unexpected " "size (or not a float type at all)") @@ -1185,7 +1185,7 @@ def test_some_float_invalid_3(): if ffi.sizeof("long double") == ffi.sizeof("double"): assert lib.neg(12.3) == -12.3 else: - e = py.test.raises(ffi.error, getattr, lib, 'neg') + e = pytest.raises(ffi.error, getattr, lib, 'neg') assert str(e.value) == ("primitive floating-point type is " "'long double', not supported for now with " "the syntax 'typedef double... xxx;'") @@ -1267,15 +1267,15 @@ def test_macro_var_callback(): def get_my_value(): raise LookupError lib.get_my_value = get_my_value - py.test.raises(ffi.error, getattr, lib, 'my_value') - py.test.raises(ffi.error, setattr, lib, 'my_value', 50) - py.test.raises(ffi.error, ffi.addressof, lib, 'my_value') + pytest.raises(ffi.error, getattr, lib, 'my_value') + pytest.raises(ffi.error, setattr, lib, 'my_value', 50) + pytest.raises(ffi.error, ffi.addressof, lib, 'my_value') @ffi.callback("int *(*)(void)") def get_my_value(): return "hello" lib.get_my_value = get_my_value - py.test.raises(ffi.error, getattr, lib, 'my_value') - e = py.test.raises(ffi.error, setattr, lib, 'my_value', 50) + pytest.raises(ffi.error, getattr, lib, 'my_value') + e = pytest.raises(ffi.error, setattr, lib, 'my_value', 50) assert str(e.value) == "global variable 'my_value' is at address NULL" def test_const_fields(): @@ -1417,8 +1417,8 @@ def test_win32_calling_convention_0(): if sys.platform == 'win32' and not 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) @@ -1503,10 +1503,10 @@ def test_win32_calling_convention_2(): ptr_call1 = ffi.addressof(lib, 'call1') ptr_call2 = ffi.addressof(lib, 'call2') if sys.platform == 'win32' and not sys.maxsize > 2**32: - py.test.raises(TypeError, lib.call1, ffi.addressof(lib, 'cb2')) - py.test.raises(TypeError, ptr_call1, ffi.addressof(lib, 'cb2')) - py.test.raises(TypeError, lib.call2, ffi.addressof(lib, 'cb1')) - py.test.raises(TypeError, ptr_call2, ffi.addressof(lib, 'cb1')) + pytest.raises(TypeError, lib.call1, ffi.addressof(lib, 'cb2')) + pytest.raises(TypeError, ptr_call1, ffi.addressof(lib, 'cb2')) + pytest.raises(TypeError, lib.call2, ffi.addressof(lib, 'cb1')) + pytest.raises(TypeError, ptr_call2, ffi.addressof(lib, 'cb1')) assert lib.call1(ffi.addressof(lib, 'cb1')) == 500*999*2 assert ptr_call1(ffi.addressof(lib, 'cb1')) == 500*999*2 assert lib.call2(ffi.addressof(lib, 'cb2')) == -500*999*3 @@ -1559,10 +1559,10 @@ def test_win32_calling_convention_3(): ptr_call1 = ffi.addressof(lib, 'call1') ptr_call2 = ffi.addressof(lib, 'call2') if sys.platform == 'win32' and not sys.maxsize > 2**32: - py.test.raises(TypeError, lib.call1, ffi.addressof(lib, 'cb2')) - py.test.raises(TypeError, ptr_call1, ffi.addressof(lib, 'cb2')) - py.test.raises(TypeError, lib.call2, ffi.addressof(lib, 'cb1')) - py.test.raises(TypeError, ptr_call2, ffi.addressof(lib, 'cb1')) + pytest.raises(TypeError, lib.call1, ffi.addressof(lib, 'cb2')) + pytest.raises(TypeError, ptr_call1, ffi.addressof(lib, 'cb2')) + pytest.raises(TypeError, lib.call2, ffi.addressof(lib, 'cb1')) + pytest.raises(TypeError, ptr_call2, ffi.addressof(lib, 'cb1')) pt = lib.call1(ffi.addressof(lib, 'cb1')) assert (pt.x, pt.y) == (-9*500*999, 9*500*999) pt = ptr_call1(ffi.addressof(lib, 'cb1')) @@ -1640,23 +1640,23 @@ def test_extern_python_bogus_name(): lib = verify(ffi, 'test_extern_python_bogus_name', "int abc;") def fn(): pass - py.test.raises(ffi.error, ffi.def_extern("unknown_name"), fn) - py.test.raises(ffi.error, ffi.def_extern("abc"), fn) + pytest.raises(ffi.error, ffi.def_extern("unknown_name"), fn) + pytest.raises(ffi.error, ffi.def_extern("abc"), fn) assert lib.abc == 0 - e = py.test.raises(ffi.error, ffi.def_extern("abc"), fn) + e = pytest.raises(ffi.error, ffi.def_extern("abc"), fn) assert str(e.value) == ("ffi.def_extern('abc'): no 'extern \"Python\"' " "function with this name") - e = py.test.raises(ffi.error, ffi.def_extern(), fn) + e = pytest.raises(ffi.error, ffi.def_extern(), fn) assert str(e.value) == ("ffi.def_extern('fn'): no 'extern \"Python\"' " "function with this name") # - py.test.raises(TypeError, ffi.def_extern(42), fn) - py.test.raises((TypeError, AttributeError), ffi.def_extern(), "foo") + pytest.raises(TypeError, ffi.def_extern(42), fn) + pytest.raises((TypeError, AttributeError), ffi.def_extern(), "foo") class X: pass x = X() x.__name__ = x - py.test.raises(TypeError, ffi.def_extern(), x) + pytest.raises(TypeError, ffi.def_extern(), x) def test_extern_python_bogus_result_type(): ffi = FFI() @@ -1755,8 +1755,8 @@ def test_extern_python_long_double(): def test_extern_python_signature(): ffi = FFI() lib = verify(ffi, 'test_extern_python_signature', "") - py.test.raises(TypeError, ffi.def_extern(425), None) - py.test.raises(TypeError, ffi.def_extern, 'a', 'b', 'c', 'd') + pytest.raises(TypeError, ffi.def_extern(425), None) + pytest.raises(TypeError, ffi.def_extern, 'a', 'b', 'c', 'd') def test_extern_python_errors(): ffi = FFI() @@ -1790,7 +1790,7 @@ def test_extern_python_errors(): assert tb.tb_frame.f_code.co_name == "bar2" # # a case where 'onerror' is not callable - py.test.raises(TypeError, ffi.def_extern(name='bar', onerror=42), + pytest.raises(TypeError, ffi.def_extern(name='bar', onerror=42), lambda x: x) def test_extern_python_stdcall(): @@ -1996,31 +1996,31 @@ def test_bool_in_cpp_2(): def test_struct_field_opaque(): ffi = FFI() ffi.cdef("struct a { struct b b; };") - e = py.test.raises(TypeError, verify, + e = pytest.raises(TypeError, verify, ffi, "test_struct_field_opaque", "?") assert str(e.value) == ("struct a: field 'a.b' is of an opaque" " type (not declared in cdef())") ffi = FFI() ffi.cdef("struct a { struct b b[2]; };") - e = py.test.raises(TypeError, verify, + e = pytest.raises(TypeError, verify, ffi, "test_struct_field_opaque", "?") assert str(e.value) == ("struct a: field 'a.b' is of an opaque" " type (not declared in cdef())") ffi = FFI() ffi.cdef("struct a { struct b b[]; };") - e = py.test.raises(TypeError, verify, + e = pytest.raises(TypeError, verify, ffi, "test_struct_field_opaque", "?") assert str(e.value) == ("struct a: field 'a.b' is of an opaque" " type (not declared in cdef())") def test_function_arg_opaque(): - py.test.skip("can currently declare a function with an opaque struct " + pytest.skip("can currently declare a function with an opaque struct " "as argument, but AFAICT it's impossible to call it later") def test_function_returns_opaque(): ffi = FFI() ffi.cdef("struct a foo(int);") - e = py.test.raises(TypeError, verify, + e = pytest.raises(TypeError, verify, ffi, "test_function_returns_opaque", "?") assert str(e.value) == ("function foo: 'struct a' is used as result type," " but is opaque") @@ -2045,7 +2045,7 @@ def test_function_returns_partial_struct(): def test_function_returns_float_complex(): if sys.platform == 'win32': - py.test.skip("MSVC may not support _Complex") + pytest.skip("MSVC may not support _Complex") ffi = FFI() ffi.cdef("float _Complex f1(float a, float b);"); lib = verify(ffi, "test_function_returns_float_complex", """ @@ -2059,7 +2059,7 @@ def test_function_returns_float_complex(): def test_function_returns_double_complex(): if sys.platform == 'win32': - py.test.skip("MSVC may not support _Complex") + pytest.skip("MSVC may not support _Complex") ffi = FFI() ffi.cdef("double _Complex f1(double a, double b);"); lib = verify(ffi, "test_function_returns_double_complex", """ @@ -2073,7 +2073,7 @@ def test_function_returns_double_complex(): def test_function_argument_float_complex(): if sys.platform == 'win32': - py.test.skip("MSVC may not support _Complex") + pytest.skip("MSVC may not support _Complex") ffi = FFI() ffi.cdef("float f1(float _Complex x);"); lib = verify(ffi, "test_function_argument_float_complex", """ @@ -2086,7 +2086,7 @@ def test_function_argument_float_complex(): def test_function_argument_double_complex(): if sys.platform == 'win32': - py.test.skip("MSVC may not support _Complex") + pytest.skip("MSVC may not support _Complex") ffi = FFI() ffi.cdef("double f1(double _Complex);"); lib = verify(ffi, "test_function_argument_double_complex", """ @@ -2119,7 +2119,7 @@ def test_typedef_array_dotdotdot(): assert ffi.sizeof("mat_t") == 6 * 7 * ffi.sizeof("int") assert len(ffi.new("mat_t")) == 6 assert len(ffi.new("mat_t")[3]) == 7 - py.test.raises(ffi.error, ffi.sizeof, "vmat_t") + pytest.raises(ffi.error, ffi.sizeof, "vmat_t") p = ffi.new("vmat_t", 4) assert ffi.sizeof(p[3]) == 8 * ffi.sizeof("int") @@ -2173,7 +2173,7 @@ def test_call_with_custom_field_pos(): struct foo g(int a, ...) { return f(); } """) assert lib.f().x == 200 - e = py.test.raises(NotImplementedError, lib.g, 0) + e = pytest.raises(NotImplementedError, lib.g, 0) assert str(e.value) == ( 'ctype \'struct foo\' not supported as return value. It is a ' 'struct declared with "...;", but the C calling convention may ' @@ -2185,7 +2185,7 @@ def test_call_with_custom_field_pos(): def test_call_with_nested_anonymous_struct(): if sys.platform == 'win32': - py.test.skip("needs a GCC extension") + pytest.skip("needs a GCC extension") ffi = FFI() ffi.cdef(""" struct foo { int a; union { int b, c; }; }; @@ -2203,7 +2203,7 @@ def test_call_with_nested_anonymous_struct(): struct foo g(int a, ...) { return f(); } """) assert lib.f().b == 200 - e = py.test.raises(NotImplementedError, lib.g, 0) + e = pytest.raises(NotImplementedError, lib.g, 0) assert str(e.value) == ( 'ctype \'struct foo\' not supported as return value. It is a ' 'struct declared with "...;", but the C calling convention may ' @@ -2229,7 +2229,7 @@ def test_call_with_bitfield(): struct foo g(int a, ...) { return f(); } """) assert lib.f().x == 11 - e = py.test.raises(NotImplementedError, lib.g, 0) + e = pytest.raises(NotImplementedError, lib.g, 0) assert str(e.value) == ( "ctype 'struct foo' not supported as return value. It is a struct " "with bit fields, which libffi does not support. Such structs are " @@ -2239,7 +2239,7 @@ def test_call_with_bitfield(): def test_call_with_zero_length_field(): if sys.platform == 'win32': - py.test.skip("zero-length field not supported by MSVC") + pytest.skip("zero-length field not supported by MSVC") ffi = FFI() ffi.cdef(""" struct foo { int a; int x[0]; }; @@ -2255,7 +2255,7 @@ def test_call_with_zero_length_field(): struct foo g(int a, ...) { return f(); } """) assert lib.f().a == 42 - e = py.test.raises(NotImplementedError, lib.g, 0) + e = pytest.raises(NotImplementedError, lib.g, 0) assert str(e.value) == ( "ctype 'struct foo' not supported as return value. It is a " "struct with a zero-length array, which libffi does not support." @@ -2279,7 +2279,7 @@ def test_call_with_union(): union foo g(int a, ...) { return f(); } """) assert lib.f().a == 42 - e = py.test.raises(NotImplementedError, lib.g, 0) + e = pytest.raises(NotImplementedError, lib.g, 0) assert str(e.value) == ( "ctype 'union foo' not supported as return value by libffi. " "Unions are only supported as return value if the function is " @@ -2288,7 +2288,7 @@ def test_call_with_union(): def test_call_with_packed_struct(): if sys.platform == 'win32': - py.test.skip("needs a GCC extension") + pytest.skip("needs a GCC extension") ffi = FFI() ffi.cdef(""" struct foo { char y; int x; }; @@ -2308,7 +2308,7 @@ def test_call_with_packed_struct(): """) assert ord(lib.f().y) == 40 assert lib.f().x == 200 - e = py.test.raises(NotImplementedError, lib.g, 0) + e = pytest.raises(NotImplementedError, lib.g, 0) assert str(e.value) == ( "ctype 'struct foo' not supported as return value. It is a " "'packed' structure, with a different layout than expected by libffi." @@ -2319,12 +2319,12 @@ def test_call_with_packed_struct(): def test_pack_not_supported(): ffi = FFI() ffi.cdef("""struct foo { char y; int x; };""", pack=2) - py.test.raises(NotImplementedError, verify, + pytest.raises(NotImplementedError, verify, ffi, "test_pack_not_supported", "") def test_gcc_visibility_hidden(): if sys.platform == 'win32': - py.test.skip("test for gcc/clang") + pytest.skip("test for gcc/clang") ffi = FFI() ffi.cdef(""" int f(int); @@ -2342,7 +2342,7 @@ def test_override_default_definition(): def test_char16_char32_type(no_cpp=False): if no_cpp is False and sys.platform == "win32": - py.test.skip("aaaaaaa why do modern MSVC compilers still define " + pytest.skip("aaaaaaa why do modern MSVC compilers still define " "a very old __cplusplus value") ffi = FFI() ffi.cdef(""" @@ -2361,9 +2361,9 @@ def test_char16_char32_type(no_cpp=False): assert lib.foo_2bytes(u+'\u1234') == u+'\u125e' assert lib.foo_4bytes(u+'\u1234') == u+'\u125e' assert lib.foo_4bytes(u+'\U00012345') == u+'\U0001236f' - py.test.raises(TypeError, lib.foo_2bytes, u+'\U00012345') - py.test.raises(TypeError, lib.foo_2bytes, 1234) - py.test.raises(TypeError, lib.foo_4bytes, 1234) + pytest.raises(TypeError, lib.foo_2bytes, u+'\U00012345') + pytest.raises(TypeError, lib.foo_2bytes, 1234) + pytest.raises(TypeError, lib.foo_4bytes, 1234) def test_char16_char32_plain_c(): test_char16_char32_type(no_cpp=True) @@ -2384,7 +2384,7 @@ def test_realize_struct_error(): lib = verify(ffi, "test_realize_struct_error", """ typedef int foo_t; struct foo_s { void (*x)(foo_t); }; """) - py.test.raises(TypeError, ffi.new, "struct foo_s *") + pytest.raises(TypeError, ffi.new, "struct foo_s *") def test_from_buffer_struct(): ffi = FFI() @@ -2482,7 +2482,7 @@ def test_struct_with_func_with_struct_arg(): int (* CompareKey)(struct BinaryTree tree); }; """) - py.test.raises(RuntimeError, ffi.new, "struct BinaryTree *") + pytest.raises(RuntimeError, ffi.new, "struct BinaryTree *") def test_passing_large_list(): ffi = FFI() diff --git a/testing/cffi1/test_verify1.py b/testing/cffi1/test_verify1.py index 45df2b3..6245281 100644 --- a/testing/cffi1/test_verify1.py +++ b/testing/cffi1/test_verify1.py @@ -1,4 +1,4 @@ -import os, sys, math, py +import os, sys, math import pytest from cffi import FFI, FFIError, VerificationError, VerificationMissing, model from cffi import CDefError @@ -63,10 +63,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: @@ -186,7 +186,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 @@ -239,7 +239,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': @@ -248,7 +248,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 @@ -268,8 +268,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() @@ -289,8 +289,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() @@ -309,8 +309,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() @@ -331,16 +331,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() @@ -387,11 +387,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: @@ -400,7 +400,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(): @@ -420,19 +420,19 @@ def test_ffi_full_struct(): check("struct foo_s { char x; int y; long *z; };") # if sys.platform != 'win32': # XXX fixme: only gives warnings - py.test.raises(VerificationError, check, + pytest.raises(VerificationError, check, "struct foo_s { char x; int y; int *z; };") # - py.test.raises(VerificationError, check, + pytest.raises(VerificationError, check, "struct foo_s { int y; long *z; };") # cdef'ed field x is missing # - e = py.test.raises(FFI.error, check, + e = pytest.raises(FFI.error, check, "struct foo_s { int y; char x; long *z; };") assert str(e.value).startswith( "struct foo_s: wrong offset for field 'x'" " (cdef says 0, but C compiler says 4)") # - e = py.test.raises(FFI.error, check, + e = pytest.raises(FFI.error, check, "struct foo_s { char x; int y; long *z; char extra; };") assert str(e.value).startswith( "struct foo_s: wrong total size" @@ -445,7 +445,7 @@ def test_ffi_full_struct(): # that replaces what is just padding in our declaration above check("struct foo_s { char x, extra; int y; long *z; };") # - e = py.test.raises(FFI.error, check, + e = pytest.raises(FFI.error, check, "struct foo_s { char x; short pad; short y; long *z; };") assert str(e.value).startswith( "struct foo_s: wrong size for field 'y'" @@ -459,9 +459,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; @@ -515,7 +515,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: @@ -566,7 +566,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[]; };") @@ -589,7 +589,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[]; };") @@ -644,7 +644,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(): @@ -691,7 +691,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" @@ -733,14 +733,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' # @@ -822,7 +822,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 @@ -978,10 +978,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; } @@ -1037,7 +1037,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. " @@ -1114,7 +1114,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() @@ -1172,7 +1172,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() @@ -1198,9 +1198,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() @@ -1252,7 +1252,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) @@ -1264,7 +1264,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; }; }; @@ -1286,16 +1286,16 @@ 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; }; }; """) # works fine now - #py.test.raises(VerificationError, ffi.verify, """ + #pytest.raises(VerificationError, ffi.verify, """ # struct foo_s { struct { int a; char e, b; }; union { char c, d; }; }; #""") @@ -1356,7 +1356,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(""" @@ -1377,7 +1377,7 @@ def test_tmpdir(): assert lib.foo(100) == 142 def test_relative_to(): - py.test.skip("not available") + pytest.skip("not available") import tempfile, os from testing.udir import udir tmpdir = tempfile.mkdtemp(dir=str(udir)) @@ -1408,7 +1408,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);") @@ -1432,13 +1432,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 @@ -1459,14 +1459,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" @@ -1475,12 +1475,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']: @@ -1500,7 +1500,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_addressof(): ffi = FFI() @@ -1522,19 +1522,19 @@ 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(): - py.test.xfail("adapt or remove") + pytest.xfail("adapt or remove") 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, @@ -1543,7 +1543,7 @@ def test_callback_in_thread(): assert result == 0 def test_keepalive_lib(): - py.test.xfail("adapt or remove") + pytest.xfail("adapt or remove") ffi = FFI() ffi.cdef("int foobar(void);") lib = ffi.verify("int foobar(void) { return 42; }") @@ -1557,7 +1557,7 @@ def test_keepalive_lib(): assert func() == 42 def test_keepalive_ffi(): - py.test.xfail("adapt or remove") + pytest.xfail("adapt or remove") ffi = FFI() ffi.cdef("int foobar(void);") lib = ffi.verify("int foobar(void) { return 42; }") @@ -1572,7 +1572,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(""" @@ -1642,11 +1642,11 @@ def test_global_array_with_dotdotdot_length(): assert repr(lib.fooarray).startswith("<cdata 'int[50]'") def test_bad_global_array_with_dotdotdot_length(): - py.test.xfail("was detected only because 23 bytes cannot be divided by 4; " + pytest.xfail("was detected only because 23 bytes cannot be divided by 4; " "redo more generally") 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() @@ -1660,7 +1660,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) == ( @@ -1849,15 +1849,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() @@ -2078,7 +2078,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") @@ -2091,7 +2091,7 @@ def test_getlasterror_working_even_with_pypys_jit(): def test_verify_dlopen_flags(): if not hasattr(sys, 'setdlopenflags'): - py.test.skip("requires sys.setdlopenflags()") + pytest.skip("requires sys.setdlopenflags()") # Careful with RTLD_GLOBAL. If by chance the FFI is not deleted # promptly, like on PyPy, then other tests may see the same # exported symbols as well. So we must not export a simple name @@ -2125,19 +2125,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 " @@ -2154,9 +2154,9 @@ def test_verify_extra_arguments(): def test_implicit_unicode_on_windows(): from cffi import FFIError 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]: @@ -2219,16 +2219,16 @@ def test_some_integer_type_for_issue73(): def test_unsupported_some_primitive_types(): ffi = FFI() - py.test.raises((FFIError, # with pycparser <= 2.17 + pytest.raises((FFIError, # with pycparser <= 2.17 CDefError), # with pycparser >= 2.18 ffi.cdef, """typedef void... foo_t;""") # ffi.cdef("typedef int... foo_t;") - py.test.raises(VerificationError, ffi.verify, "typedef float foo_t;") + pytest.raises(VerificationError, ffi.verify, "typedef float foo_t;") def test_windows_dllimport_data(): if sys.platform != 'win32': - py.test.skip("Windows only") + pytest.skip("Windows only") from testing.udir import udir tmpfile = udir.join('dllimport_data.c') tmpfile.write('int my_value = 42;\n') @@ -2278,7 +2278,7 @@ def test_share_FILE(): def test_win_common_types(): if sys.platform != 'win32': - py.test.skip("Windows only") + pytest.skip("Windows only") ffi = FFI() ffi.set_unicode(True) ffi.verify("") @@ -2292,11 +2292,11 @@ def test_win_common_types(): 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(): _only_test_on_linux_intel() @@ -2320,7 +2320,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 *);") @@ -2343,7 +2343,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/cffi1/test_zdist.py b/testing/cffi1/test_zdist.py index efc1d86..58d5bc8 100644 --- a/testing/cffi1/test_zdist.py +++ b/testing/cffi1/test_zdist.py @@ -1,4 +1,5 @@ -import sys, os, py +import sys, os +import pytest import subprocess import cffi from testing.udir import udir @@ -56,7 +57,7 @@ class TestDist(object): try: import setuptools except ImportError: - py.test.skip("setuptools not found") + pytest.skip("setuptools not found") if os.path.exists(os.path.join(self.rootdir, 'setup.py')): self.run(['setup.py', 'egg_info'], cwd=self.rootdir) TestDist._setuptools_ready = True @@ -115,7 +116,7 @@ class TestDist(object): def test_abi_emit_python_code_2(self): ffi = cffi.FFI() ffi.set_source("package_name_1.mymod", None) - py.test.raises(IOError, ffi.emit_python_code, 'unexisting/xyz.py') + pytest.raises(IOError, ffi.emit_python_code, 'unexisting/xyz.py') @from_outside def test_abi_emit_python_code_3(self): @@ -162,7 +163,7 @@ class TestDist(object): def test_api_emit_c_code_2(self): ffi = cffi.FFI() ffi.set_source("package_name_1.mymod", "/*code would be here*/") - py.test.raises(IOError, ffi.emit_c_code, 'unexisting/xyz.c') + pytest.raises(IOError, ffi.emit_c_code, 'unexisting/xyz.c') @from_outside def test_api_emit_c_code_3(self): |