Skip to content

Commit ad439f5

Browse files
committed
RF: Rename testing.test_data to testing.get_test_data
1 parent fa5f920 commit ad439f5

File tree

6 files changed

+29
-29
lines changed

6 files changed

+29
-29
lines changed

nibabel/cmdline/tests/test_conform.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
import nibabel as nib
1616
from nibabel.cmdline.conform import main
1717
from nibabel.optpkg import optional_package
18-
from nibabel.testing import test_data
18+
from nibabel.testing import get_test_data
1919

2020
_, have_scipy, _ = optional_package('scipy.ndimage')
2121
needs_scipy = unittest.skipUnless(have_scipy, 'These tests need scipy')
2222

2323

2424
@needs_scipy
2525
def test_default(tmpdir):
26-
infile = test_data(fname='anatomical.nii')
26+
infile = get_test_data(fname='anatomical.nii')
2727
outfile = tmpdir / 'output.nii.gz'
2828
main([str(infile), str(outfile)])
2929
assert outfile.isfile()
@@ -41,7 +41,7 @@ def test_default(tmpdir):
4141

4242
@needs_scipy
4343
def test_nondefault(tmpdir):
44-
infile = test_data(fname='anatomical.nii')
44+
infile = get_test_data(fname='anatomical.nii')
4545
outfile = tmpdir / 'output.nii.gz'
4646
out_shape = (100, 100, 150)
4747
voxel_size = (1, 2, 4)

nibabel/cmdline/tests/test_convert.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
import nibabel as nib
1515
from nibabel.cmdline import convert
16-
from nibabel.testing import test_data
16+
from nibabel.testing import get_test_data
1717

1818

1919
def test_convert_noop(tmp_path):
20-
infile = test_data(fname='anatomical.nii')
20+
infile = get_test_data(fname='anatomical.nii')
2121
outfile = tmp_path / 'output.nii.gz'
2222

2323
orig = nib.load(infile)
@@ -31,7 +31,7 @@ def test_convert_noop(tmp_path):
3131
assert converted.shape == orig.shape
3232
assert converted.get_data_dtype() == orig.get_data_dtype()
3333

34-
infile = test_data(fname='resampled_anat_moved.nii')
34+
infile = get_test_data(fname='resampled_anat_moved.nii')
3535

3636
with pytest.raises(FileExistsError):
3737
convert.main([str(infile), str(outfile)])
@@ -50,7 +50,7 @@ def test_convert_noop(tmp_path):
5050

5151
@pytest.mark.parametrize('data_dtype', ('u1', 'i2', 'float32', 'float', 'int64'))
5252
def test_convert_dtype(tmp_path, data_dtype):
53-
infile = test_data(fname='anatomical.nii')
53+
infile = get_test_data(fname='anatomical.nii')
5454
outfile = tmp_path / 'output.nii.gz'
5555

5656
orig = nib.load(infile)
@@ -78,7 +78,7 @@ def test_convert_dtype(tmp_path, data_dtype):
7878
],
7979
)
8080
def test_convert_by_extension(tmp_path, ext, img_class):
81-
infile = test_data(fname='anatomical.nii')
81+
infile = get_test_data(fname='anatomical.nii')
8282
outfile = tmp_path / f'output.{ext}'
8383

8484
orig = nib.load(infile)
@@ -102,7 +102,7 @@ def test_convert_by_extension(tmp_path, ext, img_class):
102102
],
103103
)
104104
def test_convert_imgtype(tmp_path, ext, img_class):
105-
infile = test_data(fname='anatomical.nii')
105+
infile = get_test_data(fname='anatomical.nii')
106106
outfile = tmp_path / f'output.{ext}'
107107

108108
orig = nib.load(infile)
@@ -118,7 +118,7 @@ def test_convert_imgtype(tmp_path, ext, img_class):
118118

119119

120120
def test_convert_nifti_int_fail(tmp_path):
121-
infile = test_data(fname='anatomical.nii')
121+
infile = get_test_data(fname='anatomical.nii')
122122
outfile = tmp_path / f'output.nii'
123123

124124
orig = nib.load(infile)

nibabel/gifti/gifti.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,8 @@ def agg_data(self, intent_code=None):
701701
Consider a surface GIFTI file:
702702
703703
>>> import nibabel as nib
704-
>>> from nibabel.testing import test_data
705-
>>> surf_img = nib.load(test_data('gifti', 'ascii.gii'))
704+
>>> from nibabel.testing import get_test_data
705+
>>> surf_img = nib.load(get_test_data('gifti', 'ascii.gii'))
706706
707707
The coordinate data, which is indicated by the ``NIFTI_INTENT_POINTSET``
708708
intent code, may be retrieved using any of the following equivalent
@@ -754,7 +754,7 @@ def agg_data(self, intent_code=None):
754754
The following image is a GIFTI file with ten (10) data arrays of the same
755755
size, and with intent code 2001 (``NIFTI_INTENT_TIME_SERIES``):
756756
757-
>>> func_img = nib.load(test_data('gifti', 'task.func.gii'))
757+
>>> func_img = nib.load(get_test_data('gifti', 'task.func.gii'))
758758
759759
When aggregating time series data, these arrays are concatenated into
760760
a single, vertex-by-timestep array:

nibabel/gifti/tests/test_gifti.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from ... import load
1515
from ...fileholders import FileHolder
1616
from ...nifti1 import data_type_codes
17-
from ...testing import test_data
17+
from ...testing import get_test_data
1818
from .. import (
1919
GiftiCoordSystem,
2020
GiftiDataArray,
@@ -35,9 +35,9 @@
3535

3636

3737
def test_agg_data():
38-
surf_gii_img = load(test_data('gifti', 'ascii.gii'))
39-
func_gii_img = load(test_data('gifti', 'task.func.gii'))
40-
shape_gii_img = load(test_data('gifti', 'rh.shape.curv.gii'))
38+
surf_gii_img = load(get_test_data('gifti', 'ascii.gii'))
39+
func_gii_img = load(get_test_data('gifti', 'task.func.gii'))
40+
shape_gii_img = load(get_test_data('gifti', 'rh.shape.curv.gii'))
4141
# add timeseries data with intent code ``none``
4242

4343
point_data = surf_gii_img.get_arrays_from_intent('pointset')[0].data
@@ -478,7 +478,7 @@ def test_darray_dtype_coercion_failures():
478478

479479

480480
def test_gifti_file_close(recwarn):
481-
gii = load(test_data('gifti', 'ascii.gii'))
481+
gii = load(get_test_data('gifti', 'ascii.gii'))
482482
with InTemporaryDirectory():
483483
gii.to_filename('test.gii')
484484
assert not any(isinstance(r.message, ResourceWarning) for r in recwarn)

nibabel/testing/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from importlib_resources.abc import Traversable
3434

3535

36-
def test_data(
36+
def get_test_data(
3737
subdir: ty.Literal['gifti', 'nicom', 'externals'] | None = None,
3838
fname: str | None = None,
3939
) -> Traversable:
@@ -52,7 +52,7 @@ def test_data(
5252

5353

5454
# set path to example data
55-
data_path = test_data()
55+
data_path = get_test_data()
5656

5757

5858
def assert_dt_equal(a, b):

nibabel/tests/test_testing.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
data_path,
1616
error_warnings,
1717
get_fresh_mod,
18+
get_test_data,
1819
suppress_warnings,
19-
test_data,
2020
)
2121

2222

@@ -171,27 +171,27 @@ def test_assert_re_in(regex, entries):
171171

172172

173173
def test_test_data():
174-
assert str(test_data()) == str(data_path) # Always get the same result
174+
assert str(get_test_data()) == str(data_path) # Always get the same result
175175
# Works the same as using __file__ and os.path utilities
176-
assert str(test_data()) == os.path.abspath(
176+
assert str(get_test_data()) == os.path.abspath(
177177
os.path.join(os.path.dirname(__file__), '..', 'tests', 'data')
178178
)
179179
# Check action of subdir and that existence checks work
180180
for subdir in ('nicom', 'gifti', 'externals'):
181-
assert test_data(subdir) == data_path.parent.parent / subdir / 'tests' / 'data'
182-
assert os.path.exists(test_data(subdir))
183-
assert not os.path.exists(test_data(subdir, 'doesnotexist'))
181+
assert get_test_data(subdir) == data_path.parent.parent / subdir / 'tests' / 'data'
182+
assert os.path.exists(get_test_data(subdir))
183+
assert not os.path.exists(get_test_data(subdir, 'doesnotexist'))
184184

185185
for subdir in ('freesurfer', 'doesnotexist'):
186186
with pytest.raises(ValueError):
187-
test_data(subdir)
187+
get_test_data(subdir)
188188

189-
assert not os.path.exists(test_data(None, 'doesnotexist'))
189+
assert not os.path.exists(get_test_data(None, 'doesnotexist'))
190190

191191
for subdir, fname in [
192192
('gifti', 'ascii.gii'),
193193
('nicom', '0.dcm'),
194194
('externals', 'example_1.nc'),
195195
(None, 'empty.tck'),
196196
]:
197-
assert os.path.exists(test_data(subdir, fname))
197+
assert os.path.exists(get_test_data(subdir, fname))

0 commit comments

Comments
 (0)