diff options
author | mattip <matti.picus@gmail.com> | 2019-12-30 20:05:00 +0200 |
---|---|---|
committer | mattip <matti.picus@gmail.com> | 2019-12-30 20:05:00 +0200 |
commit | 8a748a939feb98375eb11301262a0e3198b6c338 (patch) | |
tree | 5e66ff38065ed79b2a79280a15ef8111a8a7cb9e /numpy | |
parent | 63ef78b1cb80ae52dae115afa2463510336e6759 (diff) | |
download | numpy-8a748a939feb98375eb11301262a0e3198b6c338.tar.gz |
MAINT: refactor function out of test module
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index d801dbf91..0ef1819f8 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -20,7 +20,6 @@ import gc import weakref import pytest from contextlib import contextmanager -from test.support import no_tracing from numpy.compat import pickle @@ -97,6 +96,26 @@ def _aligned_zeros(shape, dtype=float, order="C", align=None): data.fill(0) return data +def _no_tracing(func): + """ + Decorator to temporarily turn off tracing for the duration of a test. + Needed in tests that check refcounting, otherwise the tracing itself + influences the refcounts + """ + if not hasattr(sys, 'gettrace'): + return func + else: + @functools.wraps(func) + def wrapper(*args, **kwargs): + original_trace = sys.gettrace() + try: + sys.settrace(None) + return func(*args, **kwargs) + finally: + sys.settrace(original_trace) + return wrapper + + class TestFlags(object): def setup(self): @@ -5098,7 +5117,7 @@ class TestFlat(object): class TestResize(object): - @no_tracing + @_no_tracing def test_basic(self): x = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) if IS_PYPY: @@ -5115,7 +5134,7 @@ class TestResize(object): assert_raises(ValueError, x.resize, (5, 1)) del y # avoid pyflakes unused variable warning. - @no_tracing + @_no_tracing def test_int_shape(self): x = np.eye(3) if IS_PYPY: @@ -5149,7 +5168,7 @@ class TestResize(object): assert_raises(TypeError, np.eye(3).resize, order=1) assert_raises(TypeError, np.eye(3).resize, refcheck='hi') - @no_tracing + @_no_tracing def test_freeform_shape(self): x = np.eye(3) if IS_PYPY: @@ -5158,7 +5177,7 @@ class TestResize(object): x.resize(3, 2, 1) assert_(x.shape == (3, 2, 1)) - @no_tracing + @_no_tracing def test_zeros_appended(self): x = np.eye(3) if IS_PYPY: @@ -5168,7 +5187,7 @@ class TestResize(object): assert_array_equal(x[0], np.eye(3)) assert_array_equal(x[1], np.zeros((3, 3))) - @no_tracing + @_no_tracing def test_obj_obj(self): # check memory is initialized on resize, gh-4857 a = np.ones(10, dtype=[('k', object, 2)]) @@ -7789,7 +7808,7 @@ if not IS_PYPY: d = np.ones(100) assert_(sys.getsizeof(d) < sys.getsizeof(d.reshape(100, 1, 1).copy())) - @no_tracing + @_no_tracing def test_resize(self): d = np.ones(100) old = sys.getsizeof(d) |