Skip to content

Commit 10a3ab6

Browse files
committed
TEST: Use ArrayProxy.from_header for normal tests
1 parent 40987ac commit 10a3ab6

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

nibabel/tests/test_arrayproxy.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_init():
6363
bio.seek(16)
6464
bio.write(arr.tostring(order='F'))
6565
hdr = FunkyHeader(shape)
66-
ap = ArrayProxy(bio, hdr)
66+
ap = ArrayProxy.from_header(bio, hdr)
6767
assert_true(ap.file_like is bio)
6868
assert_equal(ap.shape, shape)
6969
# shape should be read only
@@ -79,7 +79,7 @@ def test_init():
7979
bio = BytesIO()
8080
bio.seek(16)
8181
bio.write(arr.tostring(order='C'))
82-
ap = CArrayProxy(bio, FunkyHeader((2, 3, 4)))
82+
ap = CArrayProxy.from_header(bio, FunkyHeader((2, 3, 4)))
8383
assert_array_equal(np.asarray(ap), arr)
8484

8585

@@ -97,7 +97,7 @@ def test_nifti1_init():
9797
arr = np.arange(24, dtype=np.int16).reshape(shape)
9898
write_raw_data(arr, hdr, bio)
9999
hdr.set_slope_inter(2, 10)
100-
ap = ArrayProxy(bio, hdr)
100+
ap = ArrayProxy.from_header(bio, hdr)
101101
assert_true(ap.file_like == bio)
102102
assert_equal(ap.shape, shape)
103103
# Check there has been a copy of the header
@@ -110,7 +110,7 @@ def test_nifti1_init():
110110
f = open('test.nii', 'wb')
111111
write_raw_data(arr, hdr, f)
112112
f.close()
113-
ap = ArrayProxy('test.nii', hdr)
113+
ap = ArrayProxy.from_header('test.nii', hdr)
114114
assert_true(ap.file_like == 'test.nii')
115115
assert_equal(ap.shape, shape)
116116
assert_array_equal(np.asarray(ap), arr * 2.0 + 10)
@@ -130,15 +130,15 @@ def test_proxy_slicing():
130130
fobj = BytesIO()
131131
fobj.write(b'\0' * offset)
132132
fobj.write(arr.tostring(order=order))
133-
prox = klass(fobj, hdr)
133+
prox = klass.from_header(fobj, hdr)
134134
for sliceobj in slicer_samples(shape):
135135
assert_array_equal(arr[sliceobj], prox[sliceobj])
136136
# Check slicing works with scaling
137137
hdr.set_slope_inter(2.0, 1.0)
138138
fobj = BytesIO()
139139
fobj.write(b'\0' * offset)
140140
fobj.write(arr.tostring(order='F'))
141-
prox = ArrayProxy(fobj, hdr)
141+
prox = ArrayProxy.from_header(fobj, hdr)
142142
sliceobj = (None, slice(None), 1, -1)
143143
assert_array_equal(arr[sliceobj] * 2.0 + 1.0, prox[sliceobj])
144144

@@ -147,7 +147,7 @@ def test_is_proxy():
147147
# Test is_proxy function
148148
hdr = FunkyHeader((2, 3, 4))
149149
bio = BytesIO()
150-
prox = ArrayProxy(bio, hdr)
150+
prox = ArrayProxy.from_header(bio, hdr)
151151
assert_true(is_proxy(prox))
152152
assert_false(is_proxy(bio))
153153
assert_false(is_proxy(hdr))
@@ -163,7 +163,7 @@ def test_reshape_dataobj():
163163
shape = (1, 2, 3, 4)
164164
hdr = FunkyHeader(shape)
165165
bio = BytesIO()
166-
prox = ArrayProxy(bio, hdr)
166+
prox = ArrayProxy.from_header(bio, hdr)
167167
arr = np.arange(np.prod(shape), dtype=prox.dtype).reshape(shape)
168168
bio.write(b'\x00' * prox.offset + arr.tostring(order='F'))
169169
assert_array_equal(prox, arr)
@@ -198,7 +198,7 @@ def get_slope_inter(self):
198198
arr = np.arange(24, dtype=np.int32).reshape(shape, order='F')
199199
bio.write(b'\x00' * hdr.get_data_offset())
200200
bio.write(arr.tostring(order='F'))
201-
prox = ArrayProxy(bio, hdr)
201+
prox = ArrayProxy.from_header(bio, hdr)
202202
assert_array_almost_equal(np.array(prox), arr * 2.1 + 3.14)
203203
# Check unscaled read works
204204
assert_array_almost_equal(prox.get_unscaled(), arr)

nibabel/tests/test_proxy_api.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def sio_func():
233233
# Use a copy of the header to avoid changing
234234
# global header in test functions.
235235
new_hdr = hdr.copy()
236-
return (self.proxy_class(fio, new_hdr),
236+
return (self.proxy_class.from_header(fio, new_hdr),
237237
fio,
238238
new_hdr)
239239

@@ -258,7 +258,7 @@ def fname_func():
258258
# Use a copy of the header to avoid changing
259259
# global header in test functions.
260260
new_hdr = hdr.copy()
261-
return (self.proxy_class(fname, new_hdr),
261+
return (self.proxy_class.from_header(fname, new_hdr),
262262
fname,
263263
new_hdr)
264264
params = params.copy()
@@ -288,7 +288,7 @@ def validate_deprecated_header(self, pmaker, params):
288288
# Header is a copy of original
289289
assert_false(prox.header is hdr)
290290
assert_equal(prox.header, hdr)
291-
assert_equal(warns.pop(0).category, FutureWarning)
291+
assert_equal(warns.pop(0).category, DeprecationWarning)
292292

293293

294294
class TestSpm99AnalyzeProxyAPI(TestAnalyzeProxyAPI):

0 commit comments

Comments
 (0)