From 69dfdf9131c251709a396b49ddf7e45703fc09d5 Mon Sep 17 00:00:00 2001 From: da-woods Date: Wed, 14 Apr 2021 12:26:43 +0100 Subject: Disable GC-sensitive test on PyPy and remove the outdated @testcase decorator (GH-4095) * Disable GC-sensitive NumPy tests on PyPy * Removed @testcase decorator pattern that was causing tests to be run twice --- tests/buffers/bufaccess.pyx | 5 +---- tests/buffers/buffmt.pyx | 24 +---------------------- tests/memoryview/memoryviewattrs.pyx | 22 --------------------- tests/memoryview/numpy_memoryview.pyx | 37 ++++++----------------------------- tests/run/numpy_test.pyx | 20 ++++--------------- 5 files changed, 12 insertions(+), 96 deletions(-) diff --git a/tests/buffers/bufaccess.pyx b/tests/buffers/bufaccess.pyx index db36efe78..6b0b4ac30 100644 --- a/tests/buffers/bufaccess.pyx +++ b/tests/buffers/bufaccess.pyx @@ -13,8 +13,6 @@ from cpython.object cimport PyObject from cpython.ref cimport Py_INCREF, Py_DECREF cimport cython -__test__ = {} - import sys #import re exclude = []#re.compile('object').search] @@ -27,8 +25,7 @@ if getattr(sys, 'pypy_version_info', None) is not None: def testcase(func): for e in exclude: if e(func.__name__): - return func - __test__[func.__name__] = func.__doc__ + func.__doc__ = "" # disable the test return func diff --git a/tests/buffers/buffmt.pyx b/tests/buffers/buffmt.pyx index 0aa0cb325..0a9757270 100644 --- a/tests/buffers/buffmt.pyx +++ b/tests/buffers/buffmt.pyx @@ -3,10 +3,6 @@ import struct # Tests buffer format string parsing. -__test__ = {} -def testcase(func): - __test__[func.__name__] = func.__doc__ - return func from libc cimport stdlib @@ -56,7 +52,6 @@ cdef class MockBuffer: info.format = self.format info.itemsize = self.itemsize -@testcase def _int(fmt): """ >>> _int("i") @@ -78,14 +73,12 @@ def _int(fmt): """ cdef object[int] buf = MockBuffer(fmt, sizeof(int)) -@testcase def _ulong(fmt): """ >>> _ulong("L") """ cdef object[unsigned long] buf = MockBuffer(fmt, sizeof(unsigned long)) -@testcase def wrongsize(): """ >>> wrongsize() @@ -96,7 +89,6 @@ def wrongsize(): """ cdef object[float] buf = MockBuffer("f", 1) -@testcase def _obj(fmt): """ >>> _obj("O") @@ -151,7 +143,6 @@ cdef struct UnpackedStruct4: char d int e, f, g -@testcase def char3int(fmt): """ >>> char3int("ciii") @@ -185,7 +176,6 @@ def char3int(fmt): cdef object[Char3Int, ndim=1] buf = obj -@testcase def long_string(fmt): """ >>> long_string("90198s") @@ -194,7 +184,6 @@ def long_string(fmt): cdef object[LongString, ndim=1] buf = obj -@testcase def unpacked_struct(fmt): """ Native formats: @@ -218,7 +207,6 @@ def unpacked_struct(fmt): cdef struct ComplexTest: ComplexFloat a, b, c -@testcase def complex_test(fmt): """ >>> complex_test("ZfZfZf") @@ -236,7 +224,6 @@ def complex_test(fmt): cdef object[ComplexTest] buf1 = obj -@testcase def alignment_string(fmt, exc=None): """ >>> alignment_string("@i") @@ -258,7 +245,6 @@ def alignment_string(fmt, exc=None): print "fail" -@testcase def int_and_long_are_same(): """ >>> int_and_long_are_same() @@ -273,7 +259,6 @@ cdef struct MixedComplex: double real float imag -@testcase def mixed_complex_struct(): """ Triggering a specific execution path for this case. @@ -311,7 +296,6 @@ cdef packed struct PartiallyPackedStruct2: char b int c -@testcase def packed_struct(fmt): """ Assuming int is four bytes: @@ -334,7 +318,6 @@ def packed_struct(fmt): """ cdef object[PackedStruct] buf = MockBuffer(fmt, sizeof(PackedStruct)) -@testcase def partially_packed_struct(fmt): """ Assuming int is four bytes: @@ -362,7 +345,6 @@ def partially_packed_struct(fmt): cdef object[PartiallyPackedStruct] buf = MockBuffer( fmt, sizeof(PartiallyPackedStruct)) -@testcase def partially_packed_struct_2(fmt): """ Assuming int is four bytes: @@ -380,7 +362,7 @@ def partially_packed_struct_2(fmt): Traceback (most recent call last): ... ValueError: Buffer dtype mismatch; next field is at offset 8 but 5 expected - + >>> partially_packed_struct_2("ccici") Traceback (most recent call last): ... @@ -398,7 +380,6 @@ cdef packed struct PackedStructWithCharArrays: char[3] d -@testcase def packed_struct_with_strings(fmt): """ >>> packed_struct_with_strings("T{f:a:i:b:5s:c:3s:d:}") @@ -430,7 +411,6 @@ ctypedef struct PackedStructWithNDArrays: float d -@testcase def packed_struct_with_arrays(fmt): """ >>> packed_struct_with_arrays("T{(16)d:a:(16)d:b:d:c:}") @@ -440,7 +420,6 @@ def packed_struct_with_arrays(fmt): fmt, sizeof(PackedStructWithArrays)) -@testcase def unpacked_struct_with_arrays(fmt): """ >>> if struct.calcsize('P') == 8: # 64 bit @@ -453,7 +432,6 @@ def unpacked_struct_with_arrays(fmt): fmt, sizeof(UnpackedStructWithArrays)) -@testcase def packed_struct_with_ndarrays(fmt): """ >>> packed_struct_with_ndarrays("T{d:a:(2,2)d:b:f:c:f:d:}") diff --git a/tests/memoryview/memoryviewattrs.pyx b/tests/memoryview/memoryviewattrs.pyx index 66bc9da56..7322424c3 100644 --- a/tests/memoryview/memoryviewattrs.pyx +++ b/tests/memoryview/memoryviewattrs.pyx @@ -1,13 +1,6 @@ # mode: run # tag: numpy -__test__ = {} - -def testcase(func): - __test__[func.__name__] = func.__doc__ - return func - - cimport cython from cython.view cimport array @@ -15,7 +8,6 @@ import numpy as np cimport numpy as np -@testcase def test_shape_stride_suboffset(): u''' >>> test_shape_stride_suboffset() @@ -49,7 +41,6 @@ def test_shape_stride_suboffset(): print c_contig.suboffsets[0], c_contig.suboffsets[1], c_contig.suboffsets[2] -@testcase def test_copy_to(): u''' >>> test_copy_to() @@ -72,7 +63,6 @@ def test_copy_to(): print ' '.join(str(to_data[i]) for i in range(2*2*2)) -@testcase def test_overlapping_copy(): """ >>> test_overlapping_copy() @@ -88,7 +78,6 @@ def test_overlapping_copy(): assert slice[i] == 10 - 1 - i -@testcase def test_copy_return_type(): """ >>> test_copy_return_type() @@ -103,7 +92,6 @@ def test_copy_return_type(): print(f_contig[2, 2]) -@testcase def test_partly_overlapping(): """ >>> test_partly_overlapping() @@ -119,7 +107,6 @@ def test_partly_overlapping(): for i in range(5): assert slice2[i] == i + 4 -@testcase @cython.nonecheck(True) def test_nonecheck1(): u''' @@ -131,7 +118,6 @@ def test_nonecheck1(): cdef int[:,:,:] uninitialized print uninitialized.is_c_contig() -@testcase @cython.nonecheck(True) def test_nonecheck2(): u''' @@ -143,7 +129,6 @@ def test_nonecheck2(): cdef int[:,:,:] uninitialized print uninitialized.is_f_contig() -@testcase @cython.nonecheck(True) def test_nonecheck3(): u''' @@ -155,7 +140,6 @@ def test_nonecheck3(): cdef int[:,:,:] uninitialized uninitialized.copy() -@testcase @cython.nonecheck(True) def test_nonecheck4(): u''' @@ -167,7 +151,6 @@ def test_nonecheck4(): cdef int[:,:,:] uninitialized uninitialized.copy_fortran() -@testcase @cython.nonecheck(True) def test_nonecheck5(): u''' @@ -179,7 +162,6 @@ def test_nonecheck5(): cdef int[:,:,:] uninitialized uninitialized._data -@testcase def test_copy_mismatch(): u''' >>> test_copy_mismatch() @@ -193,7 +175,6 @@ def test_copy_mismatch(): mv1[...] = mv2 -@testcase def test_is_contiguous(): u""" >>> test_is_contiguous() @@ -222,7 +203,6 @@ def test_is_contiguous(): print 'strided', strided[::2].is_c_contig() -@testcase def call(): u''' >>> call() @@ -265,7 +245,6 @@ def call(): assert len(mv3) == 3 -@testcase def two_dee(): u''' >>> two_dee() @@ -313,7 +292,6 @@ def two_dee(): print (mv3._data)[0] , (mv3._data)[1] , (mv3._data)[2] , (mv3._data)[3] -@testcase def fort_two_dee(): u''' >>> fort_two_dee() diff --git a/tests/memoryview/numpy_memoryview.pyx b/tests/memoryview/numpy_memoryview.pyx index 44038bc9c..6860fafeb 100644 --- a/tests/memoryview/numpy_memoryview.pyx +++ b/tests/memoryview/numpy_memoryview.pyx @@ -36,18 +36,11 @@ def ae(*args): if x != args[0]: raise AssertionError(args) -__test__ = {} - -def testcase(f): - __test__[f.__name__] = f.__doc__ - return f - -def testcase_numpy_1_5(f): - if NUMPY_VERSION >= (1, 5) or IS_PYPY: - __test__[f.__name__] = f.__doc__ +def testcase_no_pypy(f, _is_pypy=hasattr(sys, "pypy_version_info")): + if _is_pypy: + f.__doc__ = "" # disable the tests return f - def gc_collect_if_required(): if NUMPY_VERSION >= (1, 14) or IS_PYPY: import gc @@ -58,7 +51,6 @@ def gc_collect_if_required(): ### Test slicing memoryview slices # -@testcase def test_partial_slicing(array): """ >>> test_partial_slicing(a) @@ -74,7 +66,6 @@ def test_partial_slicing(array): ae(b.strides[0], c.strides[0], obj.strides[0]) ae(b.strides[1], c.strides[1], obj.strides[1]) -@testcase def test_ellipsis(array): """ >>> test_ellipsis(a) @@ -116,7 +107,6 @@ def test_ellipsis(array): # ### Test slicing memoryview objects # -@testcase def test_partial_slicing_memoryview(array): """ >>> test_partial_slicing_memoryview(a) @@ -133,7 +123,6 @@ def test_partial_slicing_memoryview(array): ae(b.strides[0], c.strides[0], obj.strides[0]) ae(b.strides[1], c.strides[1], obj.strides[1]) -@testcase def test_ellipsis_memoryview(array): """ >>> test_ellipsis_memoryview(a) @@ -174,7 +163,6 @@ def test_ellipsis_memoryview(array): ae(e.strides[0], e_obj.strides[0]) -@testcase def test_transpose(): """ >>> test_transpose() @@ -205,7 +193,6 @@ def test_transpose(): print a[3, 2], a.T[2, 3], a_obj[3, 2], a_obj.T[2, 3], numpy_obj[3, 2], numpy_obj.T[2, 3] -@testcase def test_transpose_type(a): """ >>> a = np.zeros((5, 10), dtype=np.float64) @@ -218,12 +205,8 @@ def test_transpose_type(a): print m_transpose[6, 4] -@testcase_numpy_1_5 def test_numpy_like_attributes(cyarray): """ - For some reason this fails in numpy 1.4, with shape () and strides (40, 8) - instead of 20, 4 on my machine. Investigate this. - >>> cyarray = create_array(shape=(8, 5), mode="c") >>> test_numpy_like_attributes(cyarray) >>> test_numpy_like_attributes(cyarray.memview) @@ -239,7 +222,6 @@ def test_numpy_like_attributes(cyarray): cdef int[:, :] mslice = numarray assert ( mslice).base is numarray -@testcase_numpy_1_5 def test_copy_and_contig_attributes(a): """ >>> a = np.arange(20, dtype=np.int32).reshape(5, 4) @@ -276,7 +258,7 @@ def build_numarray(array array): def index(array array): print build_numarray(array)[3, 2] -@testcase_numpy_1_5 +@testcase_no_pypy def test_coerce_to_numpy(): """ Test coercion to NumPy arrays, especially with automatically @@ -357,6 +339,7 @@ def test_coerce_to_numpy(): 'e': 800, } + smallstructs[idx] = { 'a': 600, 'b': 700 } nestedstructs[idx] = { @@ -414,7 +397,7 @@ def test_coerce_to_numpy(): index( h_ushorts) -@testcase_numpy_1_5 +@testcase_no_pypy def test_memslice_getbuffer(): """ >>> test_memslice_getbuffer(); gc_collect_if_required() @@ -453,7 +436,6 @@ cdef packed struct StructArray: int a[4] signed char b[5] -@testcase_numpy_1_5 def test_memslice_structarray(data, dtype): """ >>> def b(s): return s.encode('ascii') @@ -509,7 +491,6 @@ def test_memslice_structarray(data, dtype): print myslice[i].a[j] print myslice[i].b.decode('ASCII') -@testcase_numpy_1_5 def test_structarray_errors(StructArray[:] a): """ >>> dtype = np.dtype([('a', '4i'), ('b', '5b')]) @@ -556,7 +537,6 @@ def stringstructtest(StringStruct[:] view): def stringtest(String[:] view): pass -@testcase_numpy_1_5 def test_string_invalid_dims(): """ >>> def b(s): return s.encode('ascii') @@ -577,7 +557,6 @@ ctypedef struct AttributesStruct: float attrib2 StringStruct attrib3 -@testcase_numpy_1_5 def test_struct_attributes(): """ >>> test_struct_attributes() @@ -633,7 +612,6 @@ cdef class SuboffsetsNoStridesBuffer(Buffer): getbuffer(self, info) info.suboffsets = self._shape -@testcase def test_null_strides(Buffer buffer_obj): """ >>> test_null_strides(Buffer()) @@ -653,7 +631,6 @@ def test_null_strides(Buffer buffer_obj): assert m2[i, j] == buffer_obj.m[i, j], (i, j, m2[i, j], buffer_obj.m[i, j]) assert m3[i, j] == buffer_obj.m[i, j] -@testcase def test_null_strides_error(buffer_obj): """ >>> test_null_strides_error(Buffer()) @@ -727,7 +704,6 @@ ctypedef struct SameTypeAfterArraysStructSimple: double b[16] double c -@testcase def same_type_after_arrays_simple(): """ >>> same_type_after_arrays_simple() @@ -749,7 +725,6 @@ ctypedef struct SameTypeAfterArraysStructComposite: double h[4] int i -@testcase def same_type_after_arrays_composite(): """ >>> same_type_after_arrays_composite() if sys.version_info[:2] >= (3, 5) else None diff --git a/tests/run/numpy_test.pyx b/tests/run/numpy_test.pyx index e81547c32..d2718a463 100644 --- a/tests/run/numpy_test.pyx +++ b/tests/run/numpy_test.pyx @@ -10,16 +10,10 @@ def little_endian(): cdef int endian_detector = 1 return (&endian_detector)[0] != 0 -__test__ = {} def testcase(f): - __test__[f.__name__] = f.__doc__ - return f - -def testcase_have_buffer_interface(f): - major, minor, *rest = np.__version__.split('.') - if (int(major), int(minor)) >= (1, 5): - __test__[f.__name__] = f.__doc__ + # testcase decorator now does nothing (following changes to doctest) + # but is a useful indicator of what functions are designed as tests return f if little_endian(): @@ -180,7 +174,7 @@ try: ('a', np.dtype('i,i')),\ ('b', np.dtype('i,i'))\ ])))) # doctest: +NORMALIZE_WHITESPACE - array([((0, 0), (0, 0)), ((1, 2), (1, 4)), ((1, 2), (1, 4))], + array([((0, 0), (0, 0)), ((1, 2), (1, 4)), ((1, 2), (1, 4))], dtype=[('a', [('f0', '!i4'), ('f1', '!i4')]), ('b', [('f0', '!i4'), ('f1', '!i4')])]) >>> print(test_nested_dtypes(np.zeros((3,), dtype=np.dtype([\ @@ -233,7 +227,7 @@ try: 8,16 >>> test_point_record() # doctest: +NORMALIZE_WHITESPACE - array([(0., 0.), (1., -1.), (2., -2.)], + array([(0., 0.), (1., -1.), (2., -2.)], dtype=[('x', '!f8'), ('y', '!f8')]) """ @@ -267,8 +261,6 @@ try: except: __doc__ = u"" -__test__[__name__] = __doc__ - def assert_dtype_sizes(): assert sizeof(np.int8_t) == 1 @@ -679,7 +671,6 @@ def get_Foo_array(): data[5].b = 9.0 return np.asarray(data).copy() -@testcase_have_buffer_interface def test_fused_ndarray(fused_ndarray a): """ >>> import cython @@ -728,9 +719,6 @@ cpdef test_fused_cpdef_ndarray(fused_ndarray a): else: print b[5] -testcase_have_buffer_interface(test_fused_cpdef_ndarray) - -@testcase_have_buffer_interface def test_fused_cpdef_ndarray_cdef_call(): """ >>> test_fused_cpdef_ndarray_cdef_call() -- cgit v1.2.1