From babc98d98570b5dbb85fb1c58b012aafa9769696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Fri, 11 Nov 2022 14:51:14 +0100 Subject: Replace py.test usage with pytest, explicitly require py for tests pytest 7.2+ no longer depends on py. It ships py.path and py.error only. See https://docs.pytest.org/en/7.2.x/changelog.html#deprecations The tests use py.code as well, hence we declare and document a test dependency on py. --- c/test_c.py | 387 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 193 insertions(+), 194 deletions(-) (limited to 'c') diff --git a/c/test_c.py b/c/test_c.py index 048711c..5fd670b 100644 --- a/c/test_c.py +++ b/c/test_c.py @@ -1,4 +1,3 @@ -import py import pytest import sys @@ -80,7 +79,7 @@ def find_and_load_library(name, flags=RTLD_NOW): assert sys.platform == 'win32' assert (sys.version_info >= (3,) or '__pypy__' in sys.builtin_module_names) - py.test.skip("dlopen(None) cannot work on Windows " + pytest.skip("dlopen(None) cannot work on Windows " "with PyPy or Python 3") return load_library(path, flags) @@ -107,7 +106,7 @@ def test_all_rtld_symbols(): RTLD_DEEPBIND def test_new_primitive_type(): - py.test.raises(KeyError, new_primitive_type, "foo") + pytest.raises(KeyError, new_primitive_type, "foo") p = new_primitive_type("signed char") assert repr(p) == "" @@ -137,7 +136,7 @@ def test_cast_to_signed_char(): assert (x != cast(q, -66)) is False def test_sizeof_type(): - py.test.raises(TypeError, sizeof, 42.5) + pytest.raises(TypeError, sizeof, 42.5) p = new_primitive_type("short") assert sizeof(p) == 2 @@ -151,7 +150,7 @@ def test_integer_types(): assert int(cast(p, max)) == max assert int(cast(p, min - 1)) == max assert int(cast(p, max + 1)) == min - py.test.raises(TypeError, cast, p, None) + pytest.raises(TypeError, cast, p, None) assert long(cast(p, min - 1)) == max assert int(cast(p, b'\x08')) == 8 assert int(cast(p, u+'\x08')) == 8 @@ -169,8 +168,8 @@ def test_integer_types(): def test_no_float_on_int_types(): p = new_primitive_type('long') - py.test.raises(TypeError, float, cast(p, 42)) - py.test.raises(TypeError, complex, cast(p, 42)) + pytest.raises(TypeError, float, cast(p, 42)) + pytest.raises(TypeError, complex, cast(p, 42)) def test_float_types(): INF = 1E200 * 1E200 @@ -190,8 +189,8 @@ def test_float_types(): assert type(int(cast(p, 1E22))) is long assert type(long(cast(p, 61.91))) is long assert type(long(cast(p, 1E22))) is long - py.test.raises(OverflowError, int, cast(p, INF)) - py.test.raises(OverflowError, int, cast(p, -INF)) + pytest.raises(OverflowError, int, cast(p, INF)) + pytest.raises(OverflowError, int, cast(p, -INF)) assert float(cast(p, 1.25)) == 1.25 assert float(cast(p, INF)) == INF assert float(cast(p, -INF)) == -INF @@ -204,7 +203,7 @@ def test_float_types(): assert float(cast(p, b'\x09')) == 9.0 assert float(cast(p, u+'\x09')) == 9.0 assert float(cast(p, True)) == 1.0 - py.test.raises(TypeError, cast, p, None) + pytest.raises(TypeError, cast, p, None) def test_complex_types(): INF = 1E200 * 1E200 @@ -217,9 +216,9 @@ def test_complex_types(): assert bool(cast(p, INF*1j)) assert bool(cast(p, -INF*1j)) # "can't convert complex to float", like CPython's "float(0j)" - py.test.raises(TypeError, int, cast(p, -150)) - py.test.raises(TypeError, long, cast(p, -150)) - py.test.raises(TypeError, float, cast(p, -150)) + pytest.raises(TypeError, int, cast(p, -150)) + pytest.raises(TypeError, long, cast(p, -150)) + pytest.raises(TypeError, float, cast(p, -150)) assert complex(cast(p, 1.25)) == 1.25 assert complex(cast(p, 1.25j)) == 1.25j assert complex(cast(p, complex(0,INF))) == complex(0,INF) @@ -235,14 +234,14 @@ def test_complex_types(): assert complex(cast(p, b'\x09')) == 9.0 + 0j assert complex(cast(p, u+'\x09')) == 9.0 + 0j assert complex(cast(p, True)) == 1.0 + 0j - py.test.raises(TypeError, cast, p, None) + pytest.raises(TypeError, cast, p, None) # - py.test.raises(TypeError, cast, new_primitive_type(name), 1+0j) + pytest.raises(TypeError, cast, new_primitive_type(name), 1+0j) # for basetype in ["char", "int", "uint64_t", "float", "double", "long double"]: baseobj = cast(new_primitive_type(basetype), 65) - py.test.raises(TypeError, complex, baseobj) + pytest.raises(TypeError, complex, baseobj) # BArray = new_array_type(new_pointer_type(p), 10) x = newp(BArray, None) @@ -256,7 +255,7 @@ def test_complex_types(): return 2 + 3j assert complex(Foo()) == 2 + 3j assert complex(cast(p, Foo())) == 2 + 3j - py.test.raises(TypeError, cast, new_primitive_type("int"), 1+0j) + pytest.raises(TypeError, cast, new_primitive_type("int"), 1+0j) def test_character_type(): p = new_primitive_type("char") @@ -294,8 +293,8 @@ def test_inspect_pointer_type(): def test_pointer_to_int(): BInt = new_primitive_type("int") - py.test.raises(TypeError, newp, BInt) - py.test.raises(TypeError, newp, BInt, None) + pytest.raises(TypeError, newp, BInt) + pytest.raises(TypeError, newp, BInt, None) BPtr = new_pointer_type(BInt) p = newp(BPtr) assert repr(p) == "" % size_of_int() @@ -307,7 +306,7 @@ def test_pointer_to_int(): assert repr(q).startswith("" # - py.test.raises(TypeError, new_array_type, new_pointer_type(p), "foo") - py.test.raises(ValueError, new_array_type, new_pointer_type(p), -42) + pytest.raises(TypeError, new_array_type, new_pointer_type(p), "foo") + pytest.raises(ValueError, new_array_type, new_pointer_type(p), -42) # p1 = new_array_type(new_pointer_type(p), None) assert repr(p1) == "" - py.test.raises(ValueError, new_array_type, new_pointer_type(p1), 42) + pytest.raises(ValueError, new_array_type, new_pointer_type(p1), 42) # p1 = new_array_type(new_pointer_type(p), 42) p2 = new_array_type(new_pointer_type(p1), 25) @@ -528,9 +527,9 @@ def test_array_type(): p2 = new_array_type(new_pointer_type(p1), None) assert repr(p2) == "" # - py.test.raises(OverflowError, + pytest.raises(OverflowError, new_array_type, new_pointer_type(p), sys.maxsize+1) - py.test.raises(OverflowError, + pytest.raises(OverflowError, new_array_type, new_pointer_type(p), sys.maxsize // 3) def test_inspect_array_type(): @@ -569,13 +568,13 @@ def test_array_instance(): with pytest.raises(IndexError) as e: a[LENGTH+100] = 500 assert ('(expected %d < %d)' % (LENGTH+100, LENGTH)) in str(e.value) - py.test.raises(TypeError, int, a) + pytest.raises(TypeError, int, a) def test_array_of_unknown_length_instance(): p = new_primitive_type("int") p1 = new_array_type(new_pointer_type(p), None) - py.test.raises(TypeError, newp, p1, None) - py.test.raises(ValueError, newp, p1, -42) + pytest.raises(TypeError, newp, p1, None) + pytest.raises(ValueError, newp, p1, -42) a = newp(p1, 42) assert len(a) == 42 for i in range(42): @@ -744,8 +743,8 @@ def test_new_struct_type(): assert repr(BStruct) == "" BPtr = new_pointer_type(BStruct) assert repr(BPtr) == "" - py.test.raises(ValueError, sizeof, BStruct) - py.test.raises(ValueError, alignof, BStruct) + pytest.raises(ValueError, sizeof, BStruct) + pytest.raises(ValueError, alignof, BStruct) def test_new_union_type(): BUnion = new_union_type("union foo") @@ -877,7 +876,7 @@ def test_union_instance(): p = newp(new_pointer_type(BUnion), {'a2': bigval}) assert p.a1 == -42 assert p.a2 == bigval - py.test.raises(OverflowError, newp, new_pointer_type(BUnion), + pytest.raises(OverflowError, newp, new_pointer_type(BUnion), {'a1': bigval}) p = newp(new_pointer_type(BUnion), []) assert p.a1 == p.a2 == 0 @@ -917,7 +916,7 @@ def test_struct_init_list(): assert s.a3 == -123 assert s.p4 == cast(BVoidP, 0) # - py.test.raises(KeyError, newp, BStructPtr, {'foobar': 0}) + pytest.raises(KeyError, newp, BStructPtr, {'foobar': 0}) # p = newp(BIntPtr, 14141) s = newp(BStructPtr, [12, 34, 56, p]) @@ -928,7 +927,7 @@ def test_struct_init_list(): assert s.p4 == cast(BVoidP, 0) assert not s.p4 # - py.test.raises(TypeError, newp, BStructPtr, [12, 34, 56, None]) + pytest.raises(TypeError, newp, BStructPtr, [12, 34, 56, None]) def test_array_in_struct(): BInt = new_primitive_type("int") @@ -944,12 +943,12 @@ def test_offsetof(): return typeoffsetof(BType, fieldname)[1] BInt = new_primitive_type("int") BStruct = new_struct_type("struct foo") - py.test.raises(TypeError, offsetof, BInt, "abc") - py.test.raises(TypeError, offsetof, BStruct, "abc") + pytest.raises(TypeError, offsetof, BInt, "abc") + pytest.raises(TypeError, offsetof, BStruct, "abc") complete_struct_or_union(BStruct, [('abc', BInt, -1), ('def', BInt, -1)]) assert offsetof(BStruct, 'abc') == 0 assert offsetof(BStruct, 'def') == size_of_int() - py.test.raises(KeyError, offsetof, BStruct, "ghi") + pytest.raises(KeyError, offsetof, BStruct, "ghi") assert offsetof(new_pointer_type(BStruct), "def") == size_of_int() def test_function_type(): @@ -987,7 +986,7 @@ def test_function_void_result(): def test_function_void_arg(): BVoid = new_void_type() BInt = new_primitive_type("int") - py.test.raises(TypeError, new_function_type, (BVoid,), BInt, False) + pytest.raises(TypeError, new_function_type, (BVoid,), BInt, False) def test_call_function_0(): BSignedChar = new_primitive_type("signed char") @@ -995,8 +994,8 @@ def test_call_function_0(): f = cast(BFunc0, _testfunc(0)) assert f(40, 2) == 42 assert f(-100, -100) == -200 + 256 - py.test.raises(OverflowError, f, 128, 0) - py.test.raises(OverflowError, f, 0, 128) + pytest.raises(OverflowError, f, 128, 0) + pytest.raises(OverflowError, f, 0, 128) def test_call_function_0_pretend_bool_result(): BSignedChar = new_primitive_type("signed char") @@ -1005,7 +1004,7 @@ def test_call_function_0_pretend_bool_result(): f = cast(BFunc0, _testfunc(0)) assert f(40, -39) is True assert f(40, -40) is False - py.test.raises(ValueError, f, 40, 2) + pytest.raises(ValueError, f, 40, 2) def test_call_function_1(): BInt = new_primitive_type("int") @@ -1079,9 +1078,9 @@ def test_call_function_6(): assert typeof(res) is BIntPtr assert res[0] == 242 - 1000 # - py.test.raises(TypeError, f, 123456) - py.test.raises(TypeError, f, "foo") - py.test.raises(TypeError, f, u+"bar") + pytest.raises(TypeError, f, 123456) + pytest.raises(TypeError, f, "foo") + pytest.raises(TypeError, f, u+"bar") def test_call_function_7(): BChar = new_primitive_type("char") @@ -1110,7 +1109,7 @@ def test_call_function_20(): f = cast(BFunc20, _testfunc(20)) x = newp(BStructPtr, {'a1': b'A', 'a2': -4042}) # can't pass a 'struct foo' - py.test.raises(TypeError, f, x[0]) + pytest.raises(TypeError, f, x[0]) def test_call_function_21(): BInt = new_primitive_type("int") @@ -1155,9 +1154,9 @@ def test_call_function_23(): assert res == 1000 * ord(b'f') res = f(cast(BVoidP, 0)) # NULL assert res == -42 - py.test.raises(TypeError, f, None) - py.test.raises(TypeError, f, 0) - py.test.raises(TypeError, f, 0.0) + pytest.raises(TypeError, f, None) + pytest.raises(TypeError, f, 0) + pytest.raises(TypeError, f, 0.0) def test_call_function_23_bis(): # declaring the function as int(unsigned char*) @@ -1178,7 +1177,7 @@ def test_call_function_23_bool_array(): f = cast(BFunc23, _testfunc(23)) res = f(b"\x01\x01") assert res == 1000 - py.test.raises(ValueError, f, b"\x02\x02") + pytest.raises(ValueError, f, b"\x02\x02") def test_cannot_pass_struct_with_array_of_length_0(): BInt = new_primitive_type("int") @@ -1187,9 +1186,9 @@ def test_cannot_pass_struct_with_array_of_length_0(): BStructP = new_pointer_type(BStruct) complete_struct_or_union(BStruct, [('a', BArray0)]) BFunc = new_function_type((BStruct,), BInt, False) - py.test.raises(NotImplementedError, cast(BFunc, 123), cast(BStructP, 123)) + pytest.raises(NotImplementedError, cast(BFunc, 123), cast(BStructP, 123)) BFunc2 = new_function_type((BInt,), BStruct, False) - py.test.raises(NotImplementedError, cast(BFunc2, 123), 123) + pytest.raises(NotImplementedError, cast(BFunc2, 123), 123) def test_call_function_9(): BInt = new_primitive_type("int") @@ -1198,8 +1197,8 @@ def test_call_function_9(): assert f(0) == 0 assert f(1, cast(BInt, 42)) == 42 assert f(2, cast(BInt, 40), cast(BInt, 2)) == 42 - py.test.raises(TypeError, f, 1, 42) - py.test.raises(TypeError, f, 2, None) + pytest.raises(TypeError, f, 1, 42) + pytest.raises(TypeError, f, 2, None) # promotion of chars and shorts to ints BSChar = new_primitive_type("signed char") BUChar = new_primitive_type("unsigned char") @@ -1218,7 +1217,7 @@ def test_call_function_24(): assert (result.imag != 2*5.1) and (abs(result.imag - 2*5.1) < 1e-5) # inexact else: f = cast(BFunc3, _testfunc(9)) - py.test.raises(NotImplementedError, f, 12.3, 34.5) + pytest.raises(NotImplementedError, f, 12.3, 34.5) def test_call_function_25(): BDouble = new_primitive_type("double") @@ -1232,7 +1231,7 @@ def test_call_function_25(): assert (result.imag != 2*5.1) and (abs(result.imag - 2*5.1) < 1e-10) # inexact else: f = cast(BFunc3, _testfunc(9)) - py.test.raises(NotImplementedError, f, 12.3, 34.5) + pytest.raises(NotImplementedError, f, 12.3, 34.5) def test_cannot_call_with_a_autocompleted_struct(): BSChar = new_primitive_type("signed char") @@ -1244,7 +1243,7 @@ def test_cannot_call_with_a_autocompleted_struct(): ('b', BSChar, -1, 0)]) BFunc = new_function_type((BStruct,), BDouble) # internally not callable dummy_func = cast(BFunc, 42) - e = py.test.raises(NotImplementedError, dummy_func, "?") + e = pytest.raises(NotImplementedError, dummy_func, "?") msg = ("ctype 'struct foo' 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. " @@ -1283,20 +1282,20 @@ def test_read_variable(): ## FIXME: this test assumes glibc specific behavior, it's not compliant with C standard ## https://bugs.pypy.org/issue1643 if not sys.platform.startswith("linux"): - py.test.skip("untested") + pytest.skip("untested") BVoidP = new_pointer_type(new_void_type()) ll = find_and_load_library('c') stderr = ll.read_variable(BVoidP, "stderr") assert stderr == cast(BVoidP, _testfunc(8)) # ll.close_lib() - py.test.raises(ValueError, ll.read_variable, BVoidP, "stderr") + pytest.raises(ValueError, ll.read_variable, BVoidP, "stderr") def test_read_variable_as_unknown_length_array(): ## FIXME: this test assumes glibc specific behavior, it's not compliant with C standard ## https://bugs.pypy.org/issue1643 if not sys.platform.startswith("linux"): - py.test.skip("untested") + pytest.skip("untested") BCharP = new_pointer_type(new_primitive_type("char")) BArray = new_array_type(BCharP, None) ll = find_and_load_library('c') @@ -1308,7 +1307,7 @@ def test_write_variable(): ## FIXME: this test assumes glibc specific behavior, it's not compliant with C standard ## https://bugs.pypy.org/issue1643 if not sys.platform.startswith("linux") or is_musl: - py.test.skip("untested") + pytest.skip("untested") BVoidP = new_pointer_type(new_void_type()) ll = find_and_load_library('c') stderr = ll.read_variable(BVoidP, "stderr") @@ -1319,7 +1318,7 @@ def test_write_variable(): assert ll.read_variable(BVoidP, "stderr") == stderr # ll.close_lib() - py.test.raises(ValueError, ll.write_variable, BVoidP, "stderr", stderr) + pytest.raises(ValueError, ll.write_variable, BVoidP, "stderr", stderr) def test_callback(): BInt = new_primitive_type("int") @@ -1333,7 +1332,7 @@ def test_callback(): assert repr(f).startswith( ", ) for most @@ -2021,7 +2020,7 @@ def test_newp_copying(): # BArray = new_array_type(new_pointer_type(BInt), None) a1 = newp(BArray, [1, 2, 3, 4]) - py.test.raises(TypeError, newp, BArray, a1) + pytest.raises(TypeError, newp, BArray, a1) BArray6 = new_array_type(new_pointer_type(BInt), 6) a1 = newp(BArray6, [10, 20, 30]) a2 = newp(BArray6, a1) @@ -2055,7 +2054,7 @@ def test_string(): p = a + 2 assert string(p) == b"llo" assert string(newp(new_array_type(BCharP, 4), b"abcd")) == b"abcd" - py.test.raises(RuntimeError, string, cast(BCharP, 0)) + pytest.raises(RuntimeError, string, cast(BCharP, 0)) assert string(a, 4) == b"hell" assert string(a, 5) == b"hello" assert string(a, 6) == b"hello" @@ -2100,14 +2099,14 @@ def test_string_typeerror(): BShort = new_primitive_type("short") BArray = new_array_type(new_pointer_type(BShort), None) a = newp(BArray, [65, 66, 67]) - py.test.raises(TypeError, string, a) + pytest.raises(TypeError, string, a) def test_bug_convert_to_ptr(): BChar = new_primitive_type("char") BCharP = new_pointer_type(BChar) BDouble = new_primitive_type("double") x = cast(BDouble, 42) - py.test.raises(TypeError, newp, new_pointer_type(BCharP), x) + pytest.raises(TypeError, newp, new_pointer_type(BCharP), x) def test_set_struct_fields(): BChar = new_primitive_type("char") @@ -2133,8 +2132,8 @@ def test_invalid_function_result_types(): BUnion = new_union_type("union foo_u") complete_struct_or_union(BUnion, []) BFunc = new_function_type((), BUnion) - py.test.raises(NotImplementedError, cast(BFunc, 123)) - py.test.raises(TypeError, new_function_type, (), BArray) + pytest.raises(NotImplementedError, cast(BFunc, 123)) + pytest.raises(TypeError, new_function_type, (), BArray) def test_struct_return_in_func(): BChar = new_primitive_type("char") @@ -2240,8 +2239,8 @@ def test_cast_with_functionptr(): complete_struct_or_union(BStruct, [('a1', BFunc, -1)]) newp(BStructPtr, [cast(BFunc, 0)]) newp(BStructPtr, [cast(BCharP, 0)]) - py.test.raises(TypeError, newp, BStructPtr, [cast(BIntP, 0)]) - py.test.raises(TypeError, newp, BStructPtr, [cast(BFunc2, 0)]) + pytest.raises(TypeError, newp, BStructPtr, [cast(BIntP, 0)]) + pytest.raises(TypeError, newp, BStructPtr, [cast(BFunc2, 0)]) def test_wchar(): _test_wchar_variant("wchar_t") @@ -2363,8 +2362,8 @@ def _test_wchar_variant(typename): assert int(w) == 0x12345 w = cast(BInt, u+'\U00012345') assert repr(w) == "" - py.test.raises(TypeError, cast, BInt, u+'') - py.test.raises(TypeError, cast, BInt, u+'XX') + pytest.raises(TypeError, cast, BInt, u+'') + pytest.raises(TypeError, cast, BInt, u+'XX') assert int(cast(BInt, u+'a')) == ord('a') # a = newp(BWCharArray, u+'hello - world') @@ -2381,7 +2380,7 @@ def _test_wchar_variant(typename): # q = cast(BWCharP, 0) assert str(q) == repr(q) - py.test.raises(RuntimeError, string, q) + pytest.raises(RuntimeError, string, q) # def cb(p): assert repr(p).startswith("= 2.7 - py.test.raises(TypeError, memoryview, c) + pytest.raises(TypeError, memoryview, c) mv1 = memoryview(buf) assert len(mv1) == len(buf) and mv1[3] in (b"t", ord(b"t")) # --mb_ass_item-- @@ -2621,7 +2620,7 @@ def test_errno(): def test_errno_callback(): if globals().get('PY_DOT_PY'): - py.test.skip("cannot run this test on py.py (e.g. fails on Windows)") + pytest.skip("cannot run this test on py.py (e.g. fails on Windows)") set_errno(95) def cb(): e = get_errno() @@ -2647,12 +2646,12 @@ def test_cast_invalid(): complete_struct_or_union(BStruct, []) p = cast(new_pointer_type(BStruct), 123456) s = p[0] - py.test.raises(TypeError, cast, BStruct, s) + pytest.raises(TypeError, cast, BStruct, s) def test_bug_float_convertion(): BDouble = new_primitive_type("double") BDoubleP = new_pointer_type(BDouble) - py.test.raises(TypeError, newp, BDoubleP, "foobar") + pytest.raises(TypeError, newp, BDoubleP, "foobar") def test_bug_delitem(): BChar = new_primitive_type("char") @@ -2670,7 +2669,7 @@ def test_bug_delattr(): del x.a1 def test_variable_length_struct(): - py.test.skip("later") + pytest.skip("later") BLong = new_primitive_type("long") BArray = new_array_type(new_pointer_type(BLong), None) BStruct = new_struct_type("struct foo") @@ -2680,7 +2679,7 @@ def test_variable_length_struct(): assert sizeof(BStruct) == size_of_long() assert alignof(BStruct) == alignof(BLong) # - py.test.raises(TypeError, newp, BStructP, None) + pytest.raises(TypeError, newp, BStructP, None) x = newp(BStructP, 5) assert sizeof(x) == 6 * size_of_long() x[4] = 123 @@ -2689,7 +2688,7 @@ def test_variable_length_struct(): x[5] assert len(x.a2) == 5 # - py.test.raises(TypeError, newp, BStructP, [123]) + pytest.raises(TypeError, newp, BStructP, [123]) x = newp(BStructP, [123, 5]) assert x.a1 == 123 assert len(x.a2) == 5 @@ -2724,7 +2723,7 @@ def test_autocast_int(): assert x[0] == 42 x = newp(BULongLongPtr, cast(BInt, 42)) assert x[0] == 42 - py.test.raises(OverflowError, newp, BULongLongPtr, cast(BInt, -42)) + pytest.raises(OverflowError, newp, BULongLongPtr, cast(BInt, -42)) x = cast(BInt, cast(BInt, 42)) assert int(x) == 42 x = cast(BInt, cast(BLongLong, 42)) @@ -2890,8 +2889,8 @@ def test_no_cdata_float(): BUInt = new_primitive_type("unsigned int") BUIntP = new_pointer_type(BUInt) BFloat = new_primitive_type("float") - py.test.raises(TypeError, newp, BIntP, cast(BFloat, 0.0)) - py.test.raises(TypeError, newp, BUIntP, cast(BFloat, 0.0)) + pytest.raises(TypeError, newp, BIntP, cast(BFloat, 0.0)) + pytest.raises(TypeError, newp, BUIntP, cast(BFloat, 0.0)) def test_bool(): BBool = new_primitive_type("_Bool") @@ -2911,10 +2910,10 @@ def test_bool(): assert newp(BBoolP, True)[0] == 1 assert newp(BBoolP, 0)[0] == 0 assert newp(BBoolP, 1)[0] == 1 - py.test.raises(TypeError, newp, BBoolP, 1.0) - py.test.raises(TypeError, newp, BBoolP, '\x00') - py.test.raises(OverflowError, newp, BBoolP, 2) - py.test.raises(OverflowError, newp, BBoolP, -1) + pytest.raises(TypeError, newp, BBoolP, 1.0) + pytest.raises(TypeError, newp, BBoolP, '\x00') + pytest.raises(OverflowError, newp, BBoolP, 2) + pytest.raises(OverflowError, newp, BBoolP, -1) BCharP = new_pointer_type(new_primitive_type("char")) p = newp(BCharP, b'\x01') q = cast(BBoolP, p) @@ -2922,7 +2921,7 @@ def test_bool(): p = newp(BCharP, b'\x00') q = cast(BBoolP, p) assert q[0] is False - py.test.raises(TypeError, string, cast(BBool, False)) + pytest.raises(TypeError, string, cast(BBool, False)) BDouble = new_primitive_type("double") assert int(cast(BBool, cast(BDouble, 0.1))) == 1 assert int(cast(BBool, cast(BDouble, 0.0))) == 0 @@ -2940,15 +2939,15 @@ def test_bool_forbidden_cases(): q = cast(BBoolP, p) with pytest.raises(ValueError): q[0] - py.test.raises(TypeError, newp, BBoolP, b'\x00') + pytest.raises(TypeError, newp, BBoolP, b'\x00') assert newp(BBoolP, 0)[0] is False assert newp(BBoolP, 1)[0] is True - py.test.raises(OverflowError, newp, BBoolP, 2) - py.test.raises(OverflowError, newp, BBoolP, -1) - py.test.raises(ValueError, newp, BBoolA, b'\x00\x01\x02') - py.test.raises(OverflowError, newp, BBoolA, [0, 1, 2]) - py.test.raises(TypeError, string, newp(BBoolP, 1)) - py.test.raises(TypeError, string, newp(BBoolA, [1])) + pytest.raises(OverflowError, newp, BBoolP, 2) + pytest.raises(OverflowError, newp, BBoolP, -1) + pytest.raises(ValueError, newp, BBoolA, b'\x00\x01\x02') + pytest.raises(OverflowError, newp, BBoolA, [0, 1, 2]) + pytest.raises(TypeError, string, newp(BBoolP, 1)) + pytest.raises(TypeError, string, newp(BBoolA, [1])) def test_typeoffsetof(): BChar = new_primitive_type("char") @@ -2957,39 +2956,39 @@ def test_typeoffsetof(): complete_struct_or_union(BStruct, [('a1', BChar, -1), ('a2', BChar, -1), ('a3', BChar, -1)]) - py.test.raises(TypeError, typeoffsetof, BStructPtr, None) - py.test.raises(TypeError, typeoffsetof, BStruct, None) + pytest.raises(TypeError, typeoffsetof, BStructPtr, None) + pytest.raises(TypeError, typeoffsetof, BStruct, None) assert typeoffsetof(BStructPtr, 'a1') == (BChar, 0) assert typeoffsetof(BStruct, 'a1') == (BChar, 0) assert typeoffsetof(BStructPtr, 'a2') == (BChar, 1) assert typeoffsetof(BStruct, 'a3') == (BChar, 2) assert typeoffsetof(BStructPtr, 'a2', 0) == (BChar, 1) assert typeoffsetof(BStruct, u+'a3') == (BChar, 2) - py.test.raises(TypeError, typeoffsetof, BStructPtr, 'a2', 1) - py.test.raises(KeyError, typeoffsetof, BStructPtr, 'a4') - py.test.raises(KeyError, typeoffsetof, BStruct, 'a5') - py.test.raises(TypeError, typeoffsetof, BStruct, 42) - py.test.raises(TypeError, typeoffsetof, BChar, 'a1') + pytest.raises(TypeError, typeoffsetof, BStructPtr, 'a2', 1) + pytest.raises(KeyError, typeoffsetof, BStructPtr, 'a4') + pytest.raises(KeyError, typeoffsetof, BStruct, 'a5') + pytest.raises(TypeError, typeoffsetof, BStruct, 42) + pytest.raises(TypeError, typeoffsetof, BChar, 'a1') def test_typeoffsetof_array(): BInt = new_primitive_type("int") BIntP = new_pointer_type(BInt) BArray = new_array_type(BIntP, None) - py.test.raises(TypeError, typeoffsetof, BArray, None) - py.test.raises(TypeError, typeoffsetof, BArray, 'a1') + pytest.raises(TypeError, typeoffsetof, BArray, None) + pytest.raises(TypeError, typeoffsetof, BArray, 'a1') assert typeoffsetof(BArray, 51) == (BInt, 51 * size_of_int()) assert typeoffsetof(BIntP, 51) == (BInt, 51 * size_of_int()) assert typeoffsetof(BArray, -51) == (BInt, -51 * size_of_int()) MAX = sys.maxsize // size_of_int() assert typeoffsetof(BArray, MAX) == (BInt, MAX * size_of_int()) assert typeoffsetof(BIntP, MAX) == (BInt, MAX * size_of_int()) - py.test.raises(OverflowError, typeoffsetof, BArray, MAX + 1) + pytest.raises(OverflowError, typeoffsetof, BArray, MAX + 1) def test_typeoffsetof_no_bitfield(): BInt = new_primitive_type("int") BStruct = new_struct_type("struct foo") complete_struct_or_union(BStruct, [('a1', BInt, 4)]) - py.test.raises(TypeError, typeoffsetof, BStruct, 'a1') + pytest.raises(TypeError, typeoffsetof, BStruct, 'a1') def test_rawaddressof(): BChar = new_primitive_type("char") @@ -3005,12 +3004,12 @@ def test_rawaddressof(): assert repr(s) == "" a = rawaddressof(BStructPtr, s, 0) assert repr(a).startswith("= (3,): def test_FILE(): if sys.platform == "win32": - py.test.skip("testing FILE not implemented") + pytest.skip("testing FILE not implemented") # BFILE = new_struct_type("struct _IO_FILE") BFILEP = new_pointer_type(BFILE) @@ -3103,7 +3102,7 @@ def test_FILE(): def test_FILE_only_for_FILE_arg(): if sys.platform == "win32": - py.test.skip("testing FILE not implemented") + pytest.skip("testing FILE not implemented") # B_NOT_FILE = new_struct_type("struct NOT_FILE") B_NOT_FILEP = new_pointer_type(B_NOT_FILE) @@ -3119,14 +3118,14 @@ def test_FILE_only_for_FILE_arg(): fr1 = posix.fdopen(fdr, 'r') fw1 = posix.fdopen(fdw, 'w') # - e = py.test.raises(TypeError, fputs, b"hello world\n", fw1) + e = pytest.raises(TypeError, fputs, b"hello world\n", fw1) assert str(e.value).startswith( "initializer for ctype 'struct NOT_FILE *' must " "be a cdata pointer, not ") def test_FILE_object(): if sys.platform == "win32": - py.test.skip("testing FILE not implemented") + pytest.skip("testing FILE not implemented") # BFILE = new_struct_type("FILE") BFILEP = new_pointer_type(BFILE) @@ -3166,7 +3165,7 @@ def test_errno_saved(): def test_GetLastError(): if sys.platform != "win32": - py.test.skip("GetLastError(): only for Windows") + pytest.skip("GetLastError(): only for Windows") # lib = find_and_load_library('KERNEL32.DLL') BInt = new_primitive_type("int") @@ -3211,7 +3210,7 @@ def test_nonstandard_integer_types(): def test_cannot_convert_unicode_to_charp(): BCharP = new_pointer_type(new_primitive_type("char")) BCharArray = new_array_type(BCharP, None) - py.test.raises(TypeError, newp, BCharArray, u+'foobar') + pytest.raises(TypeError, newp, BCharArray, u+'foobar') def test_buffer_keepalive(): BCharP = new_pointer_type(new_primitive_type("char")) @@ -3358,7 +3357,7 @@ def test_new_handle(): if wr() is not None: import gc; gc.collect() assert wr() is None - py.test.raises(RuntimeError, from_handle, cast(BCharP, 0)) + pytest.raises(RuntimeError, from_handle, cast(BCharP, 0)) def test_new_handle_cycle(): import _weakref @@ -3495,7 +3494,7 @@ def test_struct_array_no_length(): BIntP = new_pointer_type(BInt) BArray = new_array_type(BIntP, None) BStruct = new_struct_type("foo") - py.test.raises(TypeError, complete_struct_or_union, + pytest.raises(TypeError, complete_struct_or_union, BStruct, [('x', BArray), ('y', BInt)]) # @@ -3568,8 +3567,8 @@ def test_struct_array_no_length(): q = cast(new_pointer_type(BStruct), p) assert q.y[0] == 500 assert q[0].y[0] == 500 - py.test.raises(TypeError, len, q.y) - py.test.raises(TypeError, len, q[0].y) + pytest.raises(TypeError, len, q.y) + pytest.raises(TypeError, len, q[0].y) assert typeof(q.y) is BIntP assert typeof(q[0].y) is BIntP assert sizeof(q[0]) == sizeof(BStruct) @@ -3593,12 +3592,12 @@ def test_struct_array_no_length(): assert p.n == 42 # # more error cases - py.test.raises(TypeError, newp, new_pointer_type(BStruct), [100, None]) + pytest.raises(TypeError, newp, new_pointer_type(BStruct), [100, None]) BArray4 = new_array_type(BIntP, 4) BStruct4 = new_struct_type("test4") complete_struct_or_union(BStruct4, [('a', BArray4)]) # not varsized - py.test.raises(TypeError, newp, new_pointer_type(BStruct4), [None]) - py.test.raises(TypeError, newp, new_pointer_type(BStruct4), [4]) + pytest.raises(TypeError, newp, new_pointer_type(BStruct4), [None]) + pytest.raises(TypeError, newp, new_pointer_type(BStruct4), [4]) p = newp(new_pointer_type(BStruct4), [[10, 20, 30]]) assert p.a[0] == 10 assert p.a[1] == 20 @@ -3794,11 +3793,11 @@ def test_packed(): def test_packed_with_bitfields(): if sys.platform == "win32": - py.test.skip("testing gcc behavior") + pytest.skip("testing gcc behavior") BLong = new_primitive_type("long") BChar = new_primitive_type("char") BStruct = new_struct_type("struct foo") - py.test.raises(NotImplementedError, + pytest.raises(NotImplementedError, complete_struct_or_union, BStruct, [('a1', BLong, 30), ('a2', BChar, 5)], @@ -3826,7 +3825,7 @@ def test_from_buffer_not_str_unicode(): assert p1 == from_buffer(BCharA, b"foo") import gc; gc.collect() assert p1 == from_buffer(BCharA, b"foo") - py.test.raises(TypeError, from_buffer, BCharA, u+"foo") + pytest.raises(TypeError, from_buffer, BCharA, u+"foo") try: from __builtin__ import buffer except ImportError: @@ -3872,7 +3871,7 @@ def test_from_buffer_more_cases(): try: from _cffi_backend import _testbuff except ImportError: - py.test.skip("not for pypy") + pytest.skip("not for pypy") BChar = new_primitive_type("char") BCharP = new_pointer_type(BChar) BCharA = new_array_type(BCharP, None) @@ -3931,7 +3930,7 @@ def test_from_buffer_require_writable(): BCharA = new_array_type(BCharP, None) p1 = from_buffer(BCharA, b"foo", False) assert p1 == from_buffer(BCharA, b"foo", False) - py.test.raises((TypeError, BufferError), from_buffer, BCharA, b"foo", True) + pytest.raises((TypeError, BufferError), from_buffer, BCharA, b"foo", True) ba = bytearray(b"foo") p1 = from_buffer(BCharA, ba, True) p1[0] = b"g" @@ -3957,7 +3956,7 @@ def test_from_buffer_types(): with pytest.raises(IndexError): p1[-1] # - py.test.raises(TypeError, from_buffer, BInt, bytestring) + pytest.raises(TypeError, from_buffer, BInt, bytestring) # p2 = from_buffer(BIntP, bytestring) # int * assert p2 == p1 or 'PY_DOT_PY' in globals() @@ -3985,7 +3984,7 @@ def test_from_buffer_types(): assert p2 == p1 or 'PY_DOT_PY' in globals() # BIntA4 = new_array_type(BIntP, 4) # int[4]: too big - py.test.raises(ValueError, from_buffer, BIntA4, bytestring) + pytest.raises(ValueError, from_buffer, BIntA4, bytestring) # BStruct = new_struct_type("foo") complete_struct_or_union(BStruct, [('a1', BInt, -1), @@ -4029,7 +4028,7 @@ def test_from_buffer_types(): assert sizeof(BEmptyStruct) == 0 BEmptyStructP = new_pointer_type(BEmptyStruct) BEmptyStructA = new_array_type(BEmptyStructP, None) - py.test.raises(ZeroDivisionError, from_buffer, # empty[] + pytest.raises(ZeroDivisionError, from_buffer, # empty[] BEmptyStructA, bytestring) # BEmptyStructA5 = new_array_type(BEmptyStructP, 5) @@ -4135,7 +4134,7 @@ def test_memmove_readonly_readwrite(): assert list(p) == [ord("a"), ord("b"), ord("c"), 0, 0] memmove(p, bytearray(b"ABCDE"), 2) assert list(p) == [ord("A"), ord("B"), ord("c"), 0, 0] - py.test.raises((TypeError, BufferError), memmove, b"abcde", p, 3) + pytest.raises((TypeError, BufferError), memmove, b"abcde", p, 3) ba = bytearray(b"xxxxx") memmove(dest=ba, src=p, n=3) assert ba == bytearray(b"ABcxx") @@ -4146,13 +4145,13 @@ def test_memmove_sign_check(): SignedChar = new_primitive_type("signed char") SignedCharA = new_array_type(new_pointer_type(SignedChar), None) p = newp(SignedCharA, 5) - py.test.raises(ValueError, memmove, p, p + 1, -1) # not segfault + pytest.raises(ValueError, memmove, p, p + 1, -1) # not segfault def test_memmove_bad_cdata(): BInt = new_primitive_type("int") p = cast(BInt, 42) - py.test.raises(TypeError, memmove, p, bytearray(b'a'), 1) - py.test.raises(TypeError, memmove, bytearray(b'a'), p, 1) + pytest.raises(TypeError, memmove, p, bytearray(b'a'), 1) + pytest.raises(TypeError, memmove, bytearray(b'a'), p, 1) def test_dereference_null_ptr(): BInt = new_primitive_type("int") @@ -4247,9 +4246,9 @@ def test_unpack(): assert (type(result[i]) is bool) == (type(samples[i]) is bool) # BInt = new_primitive_type("int") - py.test.raises(TypeError, unpack, p) - py.test.raises(TypeError, unpack, b"foobar", 6) - py.test.raises(TypeError, unpack, cast(BInt, 42), 1) + pytest.raises(TypeError, unpack, p) + pytest.raises(TypeError, unpack, b"foobar", 6) + pytest.raises(TypeError, unpack, cast(BInt, 42), 1) # BPtr = new_pointer_type(BInt) random_ptr = cast(BPtr, -424344) @@ -4267,7 +4266,7 @@ def test_unpack(): # BStruct = new_struct_type("foo") BStructPtr = new_pointer_type(BStruct) - e = py.test.raises(ValueError, unpack, cast(BStructPtr, 42), 5) + e = pytest.raises(ValueError, unpack, cast(BStructPtr, 42), 5) assert str(e.value) == "'foo *' points to items of unknown size" complete_struct_or_union(BStruct, [('a1', BInt, -1), ('a2', BInt, -1)]) @@ -4276,11 +4275,11 @@ def test_unpack(): assert typeof(lst[0]) is BStruct assert lst[0].a1 == 4 and lst[1].a2 == 7 # - py.test.raises(RuntimeError, unpack, cast(new_pointer_type(BChar), 0), 0) - py.test.raises(RuntimeError, unpack, cast(new_pointer_type(BChar), 0), 10) + pytest.raises(RuntimeError, unpack, cast(new_pointer_type(BChar), 0), 0) + pytest.raises(RuntimeError, unpack, cast(new_pointer_type(BChar), 0), 10) # - py.test.raises(ValueError, unpack, p0, -1) - py.test.raises(ValueError, unpack, p, -1) + pytest.raises(ValueError, unpack, p0, -1) + pytest.raises(ValueError, unpack, p, -1) def test_cdata_dir(): BInt = new_primitive_type("int") @@ -4454,13 +4453,13 @@ def test_explicit_release_new_contextmgr(): def test_explicit_release_badtype(): BIntP = new_pointer_type(new_primitive_type("int")) p = cast(BIntP, 12345) - py.test.raises(ValueError, release, p) - py.test.raises(ValueError, release, p) + pytest.raises(ValueError, release, p) + pytest.raises(ValueError, release, p) BStruct = new_struct_type("struct foo") BStructP = new_pointer_type(BStruct) complete_struct_or_union(BStruct, [('p', BIntP, -1)]) pstruct = newp(BStructP) - py.test.raises(ValueError, release, pstruct[0]) + pytest.raises(ValueError, release, pstruct[0]) def test_explicit_release_badtype_contextmgr(): BIntP = new_pointer_type(new_primitive_type("int")) @@ -4526,7 +4525,7 @@ def test_explicit_release_from_buffer_contextmgr(): def test_explicit_release_bytearray_on_cpython(): if '__pypy__' in sys.builtin_module_names: - py.test.skip("pypy's bytearray are never locked") + pytest.skip("pypy's bytearray are never locked") a = bytearray(b"xyz") BChar = new_primitive_type("char") BCharP = new_pointer_type(BChar) -- cgit v1.2.1