Skip to content

Commit 4fa120b

Browse files
committed
fix: clean up some tests and remove dependency on raises_regexp
1 parent 1fd6b76 commit 4fa120b

File tree

4 files changed

+22
-28
lines changed

4 files changed

+22
-28
lines changed

nipype/algorithms/tests/test_compcor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ def test_compcor_bad_input_shapes(self):
8383
for data_shape in (shape_less_than, shape_more_than):
8484
data_file = utils.save_toy_nii(np.zeros(data_shape), 'temp.nii')
8585
interface = CompCor(realigned_file=data_file, mask_file=self.mask_file)
86-
with pytest.raises_regexp(ValueError, "dimensions"): interface.run()
86+
with pytest.raises(ValueError, message="Dimension mismatch"): interface.run()
8787

8888
def test_tcompcor_bad_input_dim(self):
8989
bad_dims = (2, 2, 2)
9090
data_file = utils.save_toy_nii(np.zeros(bad_dims), 'temp.nii')
9191
interface = TCompCor(realigned_file=data_file)
92-
with pytest.raises_regexp(ValueError, '4-D'): interface.run()
92+
with pytest.raises(ValueError, message='Not a 4D file'): interface.run()
9393

9494
def run_cc(self, ccinterface, expected_components, expected_header='CompCor'):
9595
# run

nipype/algorithms/tests/test_mesh_ops.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ def test_ident_distances(tmpdir):
3434
@pytest.mark.skipif(VTKInfo.no_tvtk(), reason="tvtk is not installed")
3535
def test_trans_distances(tmpdir):
3636
tempdir = str(tmpdir)
37-
os.chdir(tempdir)
38-
3937
from ...interfaces.vtkbase import tvtk
4038

4139
in_surf = example_data('surf01.vtk')
@@ -57,10 +55,10 @@ def test_trans_distances(tmpdir):
5755
dist.inputs.surface2 = warped_surf
5856
dist.inputs.out_file = os.path.join(tempdir, 'distance.npy')
5957
res = dist.run()
60-
npt.assert_almost_equal(res.outputs.distance, np.linalg.norm(inc), 4)
58+
assert np.allclose(res.outputs.distance, np.linalg.norm(inc), 4)
6159
dist.inputs.weighting = 'area'
6260
res = dist.run()
63-
npt.assert_almost_equal(res.outputs.distance, np.linalg.norm(inc), 4)
61+
assert np.allclose(res.outputs.distance, np.linalg.norm(inc), 4)
6462

6563

6664
@pytest.mark.skipif(VTKInfo.no_tvtk(), reason="tvtk is not installed")

nipype/interfaces/freesurfer/tests/test_model.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
# vi: set ft=python sts=4 ts=4 sw=4 et:
44

55
import os
6-
import tempfile
7-
import shutil
86
import numpy as np
97
import nibabel as nib
108

@@ -14,12 +12,11 @@
1412

1513

1614
@pytest.mark.skipif(no_freesurfer(), reason="freesurfer is not installed")
17-
def test_concatenate():
18-
tmp_dir = os.path.realpath(tempfile.mkdtemp())
19-
cwd = os.getcwd()
20-
os.chdir(tmp_dir)
21-
in1 = os.path.join(tmp_dir, 'cont1.nii')
22-
in2 = os.path.join(tmp_dir, 'cont2.nii')
15+
def test_concatenate(tmpdir):
16+
tempdir = str(tmpdir)
17+
os.chdir(tempdir)
18+
in1 = os.path.join(tempdir, 'cont1.nii')
19+
in2 = os.path.join(tempdir, 'cont2.nii')
2320
out = 'bar.nii'
2421

2522
data1 = np.zeros((3, 3, 3, 1), dtype=np.float32)
@@ -32,27 +29,27 @@ def test_concatenate():
3229

3330
# Test default behavior
3431
res = model.Concatenate(in_files=[in1, in2]).run()
35-
assert res.outputs.concatenated_file == os.path.join(tmp_dir, 'concat_output.nii.gz')
36-
assert nib.load('concat_output.nii.gz').get_data() == out_data
32+
assert res.outputs.concatenated_file == os.path.join(tempdir, 'concat_output.nii.gz')
33+
assert np.allclose(nib.load('concat_output.nii.gz').get_data(), out_data)
3734

3835
# Test specified concatenated_file
3936
res = model.Concatenate(in_files=[in1, in2], concatenated_file=out).run()
40-
assert res.outputs.concatenated_file == os.path.join(tmp_dir, out)
41-
assert nib.load(out).get_data() == out_data
37+
assert res.outputs.concatenated_file == os.path.join(tempdir, out)
38+
assert np.allclose(nib.load(out).get_data(), out_data)
4239

4340
# Test in workflow
44-
wf = pe.Workflow('test_concatenate', base_dir=tmp_dir)
41+
wf = pe.Workflow('test_concatenate', base_dir=tempdir)
4542
concat = pe.Node(model.Concatenate(in_files=[in1, in2],
4643
concatenated_file=out),
4744
name='concat')
4845
wf.add_nodes([concat])
4946
wf.run()
50-
assert nib.load(os.path.join(tmp_dir, 'test_concatenate','concat', out)).get_data()== out_data
47+
assert np.allclose(nib.load(os.path.join(tempdir,
48+
'test_concatenate',
49+
'concat', out)).get_data(),
50+
out_data)
5151

5252
# Test a simple statistic
5353
res = model.Concatenate(in_files=[in1, in2], concatenated_file=out,
5454
stats='mean').run()
55-
assert nib.load(out).get_data() == mean_data
56-
57-
os.chdir(cwd)
58-
shutil.rmtree(tmp_dir)
55+
assert np.allclose(nib.load(out).get_data(), mean_data)

nipype/interfaces/fsl/tests/test_preprocess.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,9 @@ def test_fast_list_outputs(setup_infile):
169169
def _run_and_test(opts, output_base):
170170
outputs = fsl.FAST(**opts)._list_outputs()
171171
for output in outputs.values():
172-
filenames = filename_to_list(output)
173-
if filenames is not None:
174-
for filename in filenames:
175-
assert filename[:len(output_base)] == output_base
172+
if output:
173+
for filename in filename_to_list(output):
174+
assert os.path.realpath(filename).startswith(os.path.realpath(output_base))
176175

177176
# set up
178177
tmp_infile, indir = setup_infile

0 commit comments

Comments
 (0)