Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fa6f53a

Browse files
mattipcharris
authored andcommitted
MAINT: refactor function out of test module
1 parent 9d979a7 commit fa6f53a

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

numpy/core/tests/test_multiarray.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import weakref
2121
import pytest
2222
from contextlib import contextmanager
23-
from test.support import no_tracing
2423

2524
from numpy.compat import pickle
2625

@@ -97,6 +96,26 @@ def _aligned_zeros(shape, dtype=float, order="C", align=None):
9796
data.fill(0)
9897
return data
9998

99+
def _no_tracing(func):
100+
"""
101+
Decorator to temporarily turn off tracing for the duration of a test.
102+
Needed in tests that check refcounting, otherwise the tracing itself
103+
influences the refcounts
104+
"""
105+
if not hasattr(sys, 'gettrace'):
106+
return func
107+
else:
108+
@functools.wraps(func)
109+
def wrapper(*args, **kwargs):
110+
original_trace = sys.gettrace()
111+
try:
112+
sys.settrace(None)
113+
return func(*args, **kwargs)
114+
finally:
115+
sys.settrace(original_trace)
116+
return wrapper
117+
118+
100119

101120
class TestFlags(object):
102121
def setup(self):
@@ -5098,7 +5117,7 @@ def test_refcount(self):
50985117

50995118
class TestResize(object):
51005119

5101-
@no_tracing
5120+
@_no_tracing
51025121
def test_basic(self):
51035122
x = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
51045123
if IS_PYPY:
@@ -5115,7 +5134,7 @@ def test_check_reference(self):
51155134
assert_raises(ValueError, x.resize, (5, 1))
51165135
del y # avoid pyflakes unused variable warning.
51175136

5118-
@no_tracing
5137+
@_no_tracing
51195138
def test_int_shape(self):
51205139
x = np.eye(3)
51215140
if IS_PYPY:
@@ -5149,7 +5168,7 @@ def test_invalid_arguments(self):
51495168
assert_raises(TypeError, np.eye(3).resize, order=1)
51505169
assert_raises(TypeError, np.eye(3).resize, refcheck='hi')
51515170

5152-
@no_tracing
5171+
@_no_tracing
51535172
def test_freeform_shape(self):
51545173
x = np.eye(3)
51555174
if IS_PYPY:
@@ -5158,7 +5177,7 @@ def test_freeform_shape(self):
51585177
x.resize(3, 2, 1)
51595178
assert_(x.shape == (3, 2, 1))
51605179

5161-
@no_tracing
5180+
@_no_tracing
51625181
def test_zeros_appended(self):
51635182
x = np.eye(3)
51645183
if IS_PYPY:
@@ -5168,7 +5187,7 @@ def test_zeros_appended(self):
51685187
assert_array_equal(x[0], np.eye(3))
51695188
assert_array_equal(x[1], np.zeros((3, 3)))
51705189

5171-
@no_tracing
5190+
@_no_tracing
51725191
def test_obj_obj(self):
51735192
# check memory is initialized on resize, gh-4857
51745193
a = np.ones(10, dtype=[('k', object, 2)])
@@ -7780,7 +7799,7 @@ def test_reshape(self):
77807799
d = np.ones(100)
77817800
assert_(sys.getsizeof(d) < sys.getsizeof(d.reshape(100, 1, 1).copy()))
77827801

7783-
@no_tracing
7802+
@_no_tracing
77847803
def test_resize(self):
77857804
d = np.ones(100)
77867805
old = sys.getsizeof(d)

0 commit comments

Comments
 (0)