20
20
import weakref
21
21
import pytest
22
22
from contextlib import contextmanager
23
- from test .support import no_tracing
24
23
25
24
from numpy .compat import pickle
26
25
@@ -97,6 +96,26 @@ def _aligned_zeros(shape, dtype=float, order="C", align=None):
97
96
data .fill (0 )
98
97
return data
99
98
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
+
100
119
101
120
class TestFlags (object ):
102
121
def setup (self ):
@@ -5098,7 +5117,7 @@ def test_refcount(self):
5098
5117
5099
5118
class TestResize (object ):
5100
5119
5101
- @no_tracing
5120
+ @_no_tracing
5102
5121
def test_basic (self ):
5103
5122
x = np .array ([[1 , 0 , 0 ], [0 , 1 , 0 ], [0 , 0 , 1 ]])
5104
5123
if IS_PYPY :
@@ -5115,7 +5134,7 @@ def test_check_reference(self):
5115
5134
assert_raises (ValueError , x .resize , (5 , 1 ))
5116
5135
del y # avoid pyflakes unused variable warning.
5117
5136
5118
- @no_tracing
5137
+ @_no_tracing
5119
5138
def test_int_shape (self ):
5120
5139
x = np .eye (3 )
5121
5140
if IS_PYPY :
@@ -5149,7 +5168,7 @@ def test_invalid_arguments(self):
5149
5168
assert_raises (TypeError , np .eye (3 ).resize , order = 1 )
5150
5169
assert_raises (TypeError , np .eye (3 ).resize , refcheck = 'hi' )
5151
5170
5152
- @no_tracing
5171
+ @_no_tracing
5153
5172
def test_freeform_shape (self ):
5154
5173
x = np .eye (3 )
5155
5174
if IS_PYPY :
@@ -5158,7 +5177,7 @@ def test_freeform_shape(self):
5158
5177
x .resize (3 , 2 , 1 )
5159
5178
assert_ (x .shape == (3 , 2 , 1 ))
5160
5179
5161
- @no_tracing
5180
+ @_no_tracing
5162
5181
def test_zeros_appended (self ):
5163
5182
x = np .eye (3 )
5164
5183
if IS_PYPY :
@@ -5168,7 +5187,7 @@ def test_zeros_appended(self):
5168
5187
assert_array_equal (x [0 ], np .eye (3 ))
5169
5188
assert_array_equal (x [1 ], np .zeros ((3 , 3 )))
5170
5189
5171
- @no_tracing
5190
+ @_no_tracing
5172
5191
def test_obj_obj (self ):
5173
5192
# check memory is initialized on resize, gh-4857
5174
5193
a = np .ones (10 , dtype = [('k' , object , 2 )])
@@ -7780,7 +7799,7 @@ def test_reshape(self):
7780
7799
d = np .ones (100 )
7781
7800
assert_ (sys .getsizeof (d ) < sys .getsizeof (d .reshape (100 , 1 , 1 ).copy ()))
7782
7801
7783
- @no_tracing
7802
+ @_no_tracing
7784
7803
def test_resize (self ):
7785
7804
d = np .ones (100 )
7786
7805
old = sys .getsizeof (d )
0 commit comments