diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2018-03-23 10:22:36 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2018-03-24 09:55:09 -0600 |
commit | 9f004c07c383cb30598667cee16bf0113882a70a (patch) | |
tree | e3a0a3a44280c80d4bcc771ac792b115f174e7e0 | |
parent | fbb29df68bd7f330d5a5ced2c20e9244f12f9648 (diff) | |
download | python-numpy-9f004c07c383cb30598667cee16bf0113882a70a.tar.gz python-numpy-9f004c07c383cb30598667cee16bf0113882a70a.tar.bz2 python-numpy-9f004c07c383cb30598667cee16bf0113882a70a.zip |
TST: Do not import functions beginning `test_`.
Avoids pytest collection time warnings.
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 113 | ||||
-rw-r--r-- | numpy/core/tests/test_nditer.py | 13 | ||||
-rw-r--r-- | numpy/core/tests/test_ufunc.py | 45 |
3 files changed, 95 insertions, 76 deletions
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 44e934585..ec348ff5d 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -26,11 +26,7 @@ from decimal import Decimal import numpy as np from numpy.compat import strchar, unicode -from numpy.core._multiarray_tests import ( - test_neighborhood_iterator, test_neighborhood_iterator_oob, - test_pydatamem_seteventhook_start, test_pydatamem_seteventhook_end, - test_inplace_increment, get_buffer_info, test_as_c_array, - ) +import numpy.core._multiarray_tests as _multiarray_tests from numpy.testing import ( run_module_suite, assert_, assert_raises, assert_warns, assert_equal, assert_almost_equal, assert_array_equal, assert_raises_regex, @@ -5807,24 +5803,24 @@ class TestNeighborhoodIter(object): np.array([[0, 0, 0], [0, 1, 0]], dtype=dt), np.array([[0, 0, 1], [0, 2, 3]], dtype=dt), np.array([[0, 1, 0], [2, 3, 0]], dtype=dt)] - l = test_neighborhood_iterator(x, [-1, 0, -1, 1], x[0], - NEIGH_MODE['zero']) + l = _multiarray_tests.test_neighborhood_iterator( + x, [-1, 0, -1, 1], x[0], NEIGH_MODE['zero']) assert_array_equal(l, r) r = [np.array([[1, 1, 1], [1, 0, 1]], dtype=dt), np.array([[1, 1, 1], [0, 1, 1]], dtype=dt), np.array([[1, 0, 1], [1, 2, 3]], dtype=dt), np.array([[0, 1, 1], [2, 3, 1]], dtype=dt)] - l = test_neighborhood_iterator(x, [-1, 0, -1, 1], x[0], - NEIGH_MODE['one']) + l = _multiarray_tests.test_neighborhood_iterator( + x, [-1, 0, -1, 1], x[0], NEIGH_MODE['one']) assert_array_equal(l, r) r = [np.array([[4, 4, 4], [4, 0, 1]], dtype=dt), np.array([[4, 4, 4], [0, 1, 4]], dtype=dt), np.array([[4, 0, 1], [4, 2, 3]], dtype=dt), np.array([[0, 1, 4], [2, 3, 4]], dtype=dt)] - l = test_neighborhood_iterator(x, [-1, 0, -1, 1], 4, - NEIGH_MODE['constant']) + l = _multiarray_tests.test_neighborhood_iterator( + x, [-1, 0, -1, 1], 4, NEIGH_MODE['constant']) assert_array_equal(l, r) def test_simple2d(self): @@ -5839,8 +5835,8 @@ class TestNeighborhoodIter(object): np.array([[0, 1, 1], [0, 1, 1]], dtype=dt), np.array([[0, 0, 1], [2, 2, 3]], dtype=dt), np.array([[0, 1, 1], [2, 3, 3]], dtype=dt)] - l = test_neighborhood_iterator(x, [-1, 0, -1, 1], x[0], - NEIGH_MODE['mirror']) + l = _multiarray_tests.test_neighborhood_iterator( + x, [-1, 0, -1, 1], x[0], NEIGH_MODE['mirror']) assert_array_equal(l, r) def test_mirror2d(self): @@ -5854,15 +5850,18 @@ class TestNeighborhoodIter(object): # Test padding with constant values x = np.linspace(1, 5, 5).astype(dt) r = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 0]] - l = test_neighborhood_iterator(x, [-1, 1], x[0], NEIGH_MODE['zero']) + l = _multiarray_tests.test_neighborhood_iterator( + x, [-1, 1], x[0], NEIGH_MODE['zero']) assert_array_equal(l, r) r = [[1, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 1]] - l = test_neighborhood_iterator(x, [-1, 1], x[0], NEIGH_MODE['one']) + l = _multiarray_tests.test_neighborhood_iterator( + x, [-1, 1], x[0], NEIGH_MODE['one']) assert_array_equal(l, r) r = [[x[4], 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, x[4]]] - l = test_neighborhood_iterator(x, [-1, 1], x[4], NEIGH_MODE['constant']) + l = _multiarray_tests.test_neighborhood_iterator( + x, [-1, 1], x[4], NEIGH_MODE['constant']) assert_array_equal(l, r) def test_simple_float(self): @@ -5876,7 +5875,8 @@ class TestNeighborhoodIter(object): x = np.linspace(1, 5, 5).astype(dt) r = np.array([[2, 1, 1, 2, 3], [1, 1, 2, 3, 4], [1, 2, 3, 4, 5], [2, 3, 4, 5, 5], [3, 4, 5, 5, 4]], dtype=dt) - l = test_neighborhood_iterator(x, [-2, 2], x[1], NEIGH_MODE['mirror']) + l = _multiarray_tests.test_neighborhood_iterator( + x, [-2, 2], x[1], NEIGH_MODE['mirror']) assert_([i.dtype == dt for i in l]) assert_array_equal(l, r) @@ -5891,7 +5891,8 @@ class TestNeighborhoodIter(object): x = np.linspace(1, 5, 5).astype(dt) r = np.array([[4, 5, 1, 2, 3], [5, 1, 2, 3, 4], [1, 2, 3, 4, 5], [2, 3, 4, 5, 1], [3, 4, 5, 1, 2]], dtype=dt) - l = test_neighborhood_iterator(x, [-2, 2], x[0], NEIGH_MODE['circular']) + l = _multiarray_tests.test_neighborhood_iterator( + x, [-2, 2], x[0], NEIGH_MODE['circular']) assert_array_equal(l, r) def test_circular(self): @@ -5914,8 +5915,8 @@ class TestStackedNeighborhoodIter(object): np.array([3], dtype=dt), np.array([0], dtype=dt), np.array([0], dtype=dt)] - l = test_neighborhood_iterator_oob(x, [-2, 4], NEIGH_MODE['zero'], - [0, 0], NEIGH_MODE['zero']) + l = _multiarray_tests.test_neighborhood_iterator_oob( + x, [-2, 4], NEIGH_MODE['zero'], [0, 0], NEIGH_MODE['zero']) assert_array_equal(l, r) r = [np.array([1, 0, 1], dtype=dt), @@ -5923,8 +5924,8 @@ class TestStackedNeighborhoodIter(object): np.array([1, 2, 3], dtype=dt), np.array([2, 3, 0], dtype=dt), np.array([3, 0, 1], dtype=dt)] - l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['zero'], - [-1, 1], NEIGH_MODE['one']) + l = _multiarray_tests.test_neighborhood_iterator_oob( + x, [-1, 3], NEIGH_MODE['zero'], [-1, 1], NEIGH_MODE['one']) assert_array_equal(l, r) # 2nd simple, 1d test: stacking 2 neigh iterators, mixing const padding and @@ -5938,8 +5939,8 @@ class TestStackedNeighborhoodIter(object): np.array([1, 2, 3], dtype=dt), np.array([2, 3, 3], dtype=dt), np.array([3, 3, 0], dtype=dt)] - l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['mirror'], - [-1, 1], NEIGH_MODE['zero']) + l = _multiarray_tests.test_neighborhood_iterator_oob( + x, [-1, 3], NEIGH_MODE['mirror'], [-1, 1], NEIGH_MODE['zero']) assert_array_equal(l, r) # Stacking mirror on top of zero @@ -5949,8 +5950,8 @@ class TestStackedNeighborhoodIter(object): np.array([0, 1, 2], dtype=dt), np.array([1, 2, 3], dtype=dt), np.array([2, 3, 0], dtype=dt)] - l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['zero'], - [-2, 0], NEIGH_MODE['mirror']) + l = _multiarray_tests.test_neighborhood_iterator_oob( + x, [-1, 3], NEIGH_MODE['zero'], [-2, 0], NEIGH_MODE['mirror']) assert_array_equal(l, r) # Stacking mirror on top of zero: 2nd @@ -5960,8 +5961,8 @@ class TestStackedNeighborhoodIter(object): np.array([2, 3, 0], dtype=dt), np.array([3, 0, 0], dtype=dt), np.array([0, 0, 3], dtype=dt)] - l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['zero'], - [0, 2], NEIGH_MODE['mirror']) + l = _multiarray_tests.test_neighborhood_iterator_oob( + x, [-1, 3], NEIGH_MODE['zero'], [0, 2], NEIGH_MODE['mirror']) assert_array_equal(l, r) # Stacking mirror on top of zero: 3rd @@ -5971,8 +5972,8 @@ class TestStackedNeighborhoodIter(object): np.array([0, 1, 2, 3, 0], dtype=dt), np.array([1, 2, 3, 0, 0], dtype=dt), np.array([2, 3, 0, 0, 3], dtype=dt)] - l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['zero'], - [-2, 2], NEIGH_MODE['mirror']) + l = _multiarray_tests.test_neighborhood_iterator_oob( + x, [-1, 3], NEIGH_MODE['zero'], [-2, 2], NEIGH_MODE['mirror']) assert_array_equal(l, r) # 3rd simple, 1d test: stacking 2 neigh iterators, mixing const padding and @@ -5986,8 +5987,8 @@ class TestStackedNeighborhoodIter(object): np.array([1, 2, 3], dtype=dt), np.array([2, 3, 1], dtype=dt), np.array([3, 1, 0], dtype=dt)] - l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['circular'], - [-1, 1], NEIGH_MODE['zero']) + l = _multiarray_tests.test_neighborhood_iterator_oob( + x, [-1, 3], NEIGH_MODE['circular'], [-1, 1], NEIGH_MODE['zero']) assert_array_equal(l, r) # Stacking mirror on top of zero @@ -5997,8 +5998,8 @@ class TestStackedNeighborhoodIter(object): np.array([0, 1, 2], dtype=dt), np.array([1, 2, 3], dtype=dt), np.array([2, 3, 0], dtype=dt)] - l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['zero'], - [-2, 0], NEIGH_MODE['circular']) + l = _multiarray_tests.test_neighborhood_iterator_oob( + x, [-1, 3], NEIGH_MODE['zero'], [-2, 0], NEIGH_MODE['circular']) assert_array_equal(l, r) # Stacking mirror on top of zero: 2nd @@ -6008,8 +6009,8 @@ class TestStackedNeighborhoodIter(object): np.array([2, 3, 0], dtype=dt), np.array([3, 0, 0], dtype=dt), np.array([0, 0, 1], dtype=dt)] - l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['zero'], - [0, 2], NEIGH_MODE['circular']) + l = _multiarray_tests.test_neighborhood_iterator_oob( + x, [-1, 3], NEIGH_MODE['zero'], [0, 2], NEIGH_MODE['circular']) assert_array_equal(l, r) # Stacking mirror on top of zero: 3rd @@ -6019,8 +6020,8 @@ class TestStackedNeighborhoodIter(object): np.array([0, 1, 2, 3, 0], dtype=dt), np.array([1, 2, 3, 0, 0], dtype=dt), np.array([2, 3, 0, 0, 1], dtype=dt)] - l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['zero'], - [-2, 2], NEIGH_MODE['circular']) + l = _multiarray_tests.test_neighborhood_iterator_oob( + x, [-1, 3], NEIGH_MODE['zero'], [-2, 2], NEIGH_MODE['circular']) assert_array_equal(l, r) # 4th simple, 1d test: stacking 2 neigh iterators, but with lower iterator @@ -6031,24 +6032,24 @@ class TestStackedNeighborhoodIter(object): # array x = np.array([1, 2, 3], dtype=dt) r = [np.array([1, 2, 3, 0], dtype=dt)] - l = test_neighborhood_iterator_oob(x, [1, 1], NEIGH_MODE['zero'], - [-1, 2], NEIGH_MODE['zero']) + l = _multiarray_tests.test_neighborhood_iterator_oob( + x, [1, 1], NEIGH_MODE['zero'], [-1, 2], NEIGH_MODE['zero']) assert_array_equal(l, r) # Stacking mirror on top of zero, first neighborhood strictly inside the # array x = np.array([1, 2, 3], dtype=dt) r = [np.array([1, 2, 3, 3], dtype=dt)] - l = test_neighborhood_iterator_oob(x, [1, 1], NEIGH_MODE['zero'], - [-1, 2], NEIGH_MODE['mirror']) + l = _multiarray_tests.test_neighborhood_iterator_oob( + x, [1, 1], NEIGH_MODE['zero'], [-1, 2], NEIGH_MODE['mirror']) assert_array_equal(l, r) # Stacking mirror on top of zero, first neighborhood strictly inside the # array x = np.array([1, 2, 3], dtype=dt) r = [np.array([1, 2, 3, 1], dtype=dt)] - l = test_neighborhood_iterator_oob(x, [1, 1], NEIGH_MODE['zero'], - [-1, 2], NEIGH_MODE['circular']) + l = _multiarray_tests.test_neighborhood_iterator_oob( + x, [1, 1], NEIGH_MODE['zero'], [-1, 2], NEIGH_MODE['circular']) assert_array_equal(l, r) class TestWarnings(object): @@ -6432,7 +6433,9 @@ class TestNewBufferProtocol(object): def test_export_flags(self): # Check SIMPLE flag, see also gh-3613 (exception should be BufferError) - assert_raises(ValueError, get_buffer_info, np.arange(5)[::2], ('SIMPLE',)) + assert_raises(ValueError, + _multiarray_tests.get_buffer_info, + np.arange(5)[::2], ('SIMPLE',)) def test_padding(self): for j in range(8): @@ -6488,10 +6491,12 @@ class TestNewBufferProtocol(object): arr = np.ones((1, 10)) if arr.flags.f_contiguous: - shape, strides = get_buffer_info(arr, ['F_CONTIGUOUS']) + shape, strides = _multiarray_tests.get_buffer_info( + arr, ['F_CONTIGUOUS']) assert_(strides[0] == 8) arr = np.ones((10, 1), order='F') - shape, strides = get_buffer_info(arr, ['C_CONTIGUOUS']) + shape, strides = _multiarray_tests.get_buffer_info( + arr, ['C_CONTIGUOUS']) assert_(strides[-1] == 8) def test_out_of_order_fields(self): @@ -6634,13 +6639,13 @@ class TestMemEventHook(object): def test_mem_seteventhook(self): # The actual tests are within the C code in # multiarray/_multiarray_tests.c.src - test_pydatamem_seteventhook_start() + _multiarray_tests.test_pydatamem_seteventhook_start() # force an allocation and free of a numpy array # needs to be larger then limit of small memory cacher in ctors.c a = np.zeros(1000) del a gc.collect() - test_pydatamem_seteventhook_end() + _multiarray_tests.test_pydatamem_seteventhook_end() class TestMapIter(object): def test_mapiter(self): @@ -6652,7 +6657,7 @@ class TestMapIter(object): [0, 0, 2, 3]) vals = [50, 50, 30, 16] - test_inplace_increment(a, index, vals) + _multiarray_tests.test_inplace_increment(a, index, vals) assert_equal(a, [[0.00, 1., 2.0, 19.], [104., 5., 6.0, 7.0], [8.00, 9., 40., 11.]]) @@ -6660,24 +6665,24 @@ class TestMapIter(object): b = np.arange(6).astype(float) index = (np.array([1, 2, 0]),) vals = [50, 4, 100.1] - test_inplace_increment(b, index, vals) + _multiarray_tests.test_inplace_increment(b, index, vals) assert_equal(b, [100.1, 51., 6., 3., 4., 5.]) class TestAsCArray(object): def test_1darray(self): array = np.arange(24, dtype=np.double) - from_c = test_as_c_array(array, 3) + from_c = _multiarray_tests.test_as_c_array(array, 3) assert_equal(array[3], from_c) def test_2darray(self): array = np.arange(24, dtype=np.double).reshape(3, 8) - from_c = test_as_c_array(array, 2, 4) + from_c = _multiarray_tests.test_as_c_array(array, 2, 4) assert_equal(array[2, 4], from_c) def test_3darray(self): array = np.arange(24, dtype=np.double).reshape(2, 3, 4) - from_c = test_as_c_array(array, 1, 2, 3) + from_c = _multiarray_tests.test_as_c_array(array, 1, 2, 3) assert_equal(array[1, 2, 3], from_c) diff --git a/numpy/core/tests/test_nditer.py b/numpy/core/tests/test_nditer.py index 6b1152e09..9d8f4f06a 100644 --- a/numpy/core/tests/test_nditer.py +++ b/numpy/core/tests/test_nditer.py @@ -4,8 +4,8 @@ import sys import warnings import numpy as np +import numpy.core._multiarray_tests as _multiarray_tests from numpy import array, arange, nditer, all -from numpy.core._multiarray_tests import test_nditer_too_large from numpy.testing import ( run_module_suite, assert_, assert_equal, assert_array_equal, assert_raises, assert_warns, dec, HAS_REFCOUNT, suppress_warnings @@ -2697,18 +2697,19 @@ def test_iter_too_large_with_multiindex(): # arrays are now too large to be broadcast. The different modes test # different nditer functionality with or without GIL. for mode in range(6): - assert_raises(ValueError, test_nditer_too_large, arrays, -1, mode) + with assert_raises(ValueError): + _multiarray_tests.test_nditer_too_large(arrays, -1, mode) # but if we do nothing with the nditer, it can be constructed: - test_nditer_too_large(arrays, -1, 7) + _multiarray_tests.test_nditer_too_large(arrays, -1, 7) # When an axis is removed, things should work again (half the time): for i in range(num): for mode in range(6): # an axis with size 1024 is removed: - test_nditer_too_large(arrays, i*2, mode) + _multiarray_tests.test_nditer_too_large(arrays, i*2, mode) # an axis with size 1 is removed: - assert_raises(ValueError, test_nditer_too_large, - arrays, i*2 + 1, mode) + with assert_raises(ValueError): + _multiarray_tests.test_nditer_too_large(arrays, i*2 + 1, mode) if __name__ == "__main__": diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py index 0dc12b144..b690c8132 100644 --- a/numpy/core/tests/test_ufunc.py +++ b/numpy/core/tests/test_ufunc.py @@ -6,7 +6,7 @@ import itertools import numpy as np import numpy.core._umath_tests as umt import numpy.core._operand_flag_tests as opflag_tests -from numpy.core._rational_tests import rational, test_add, test_add_rationals +import numpy.core._rational_tests as _rational_tests from numpy.testing import ( run_module_suite, assert_, assert_equal, assert_raises, assert_array_equal, assert_almost_equal, assert_array_almost_equal, @@ -43,7 +43,8 @@ class TestUfunc(object): # Check that ufunc not defined in the top level numpy namespace such as # numpy.core._rational_tests.test_add can also be pickled - assert_(pickle.loads(pickle.dumps(test_add)) is test_add) + res = pickle.loads(pickle.dumps(_rational_tests.test_add)) + assert_(res is _rational_tests.test_add) def test_pickle_withstring(self): import pickle @@ -1143,15 +1144,17 @@ class TestUfunc(object): a = np.array([0, 1, 2], dtype='i8') b = np.array([0, 1, 2], dtype='i8') - c = np.empty(3, dtype=rational) + c = np.empty(3, dtype=_rational_tests.rational) # Output must be specified so numpy knows what # ufunc signature to look for - result = test_add(a, b, c) - assert_equal(result, np.array([0, 2, 4], dtype=rational)) + result = _rational_tests.test_add(a, b, c) + target = np.array([0, 2, 4], dtype=_rational_tests.rational) + assert_equal(result, target) # no output type should raise TypeError - assert_raises(TypeError, test_add, a, b) + with assert_raises(TypeError): + _rational_tests.test_add(a, b) def test_operand_flags(self): a = np.arange(16, dtype='l').reshape(4, 4) @@ -1176,20 +1179,30 @@ class TestUfunc(object): assert_equal(result, np.array([(2, 4, 6)], dtype='u8,u8,u8')) def test_custom_ufunc(self): - a = np.array([rational(1, 2), rational(1, 3), rational(1, 4)], - dtype=rational) - b = np.array([rational(1, 2), rational(1, 3), rational(1, 4)], - dtype=rational) - - result = test_add_rationals(a, b) - expected = np.array([rational(1), rational(2, 3), rational(1, 2)], - dtype=rational) + a = np.array( + [_rational_tests.rational(1, 2), + _rational_tests.rational(1, 3), + _rational_tests.rational(1, 4)], + dtype=_rational_tests.rational) + b = np.array( + [_rational_tests.rational(1, 2), + _rational_tests.rational(1, 3), + _rational_tests.rational(1, 4)], + dtype=_rational_tests.rational) + + result = _rational_tests.test_add_rationals(a, b) + expected = np.array( + [_rational_tests.rational(1), + _rational_tests.rational(2, 3), + _rational_tests.rational(1, 2)], + dtype=_rational_tests.rational) assert_equal(result, expected) def test_custom_ufunc_forced_sig(self): # gh-9351 - looking for a non-first userloop would previously hang - assert_raises(TypeError, - np.multiply, rational(1), 1, signature=(rational, int, None)) + with assert_raises(TypeError): + np.multiply(_rational_tests.rational(1), 1, + signature=(_rational_tests.rational, int, None)) def test_custom_array_like(self): |