Skip to content

Commit 82f0dfa

Browse files
committed
RF: move test_spaces params to function
Moving the parameters to a function allows me to use the same parameters for testing the resample_to_output function (coming soon to a repo near you).
1 parent c3a4f54 commit 82f0dfa

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

nibabel/tests/test_spaces.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,14 @@ def assert_all_in(in_shape, in_affine, out_shape, out_affine):
3535
assert_true(np.all(out_grid < np.array(out_shape) + TINY))
3636

3737

38-
def test_vox2out_vox():
39-
# Test world space bounding box
40-
# Test basic case, identity, no voxel sizes passed
41-
shape, aff = vox2out_vox(((2, 3, 4), np.eye(4)))
42-
assert_array_equal(shape, (2, 3, 4))
43-
assert_array_equal(aff, np.eye(4))
38+
def get_outspace_params():
39+
# Return in_shape, in_aff, vox, out_shape, out_aff for output space tests
40+
# Put in function to use also for resample_to_output tests
4441
# Some affines as input to the tests
4542
trans_123 = [[1, 0, 0, 1], [0, 1, 0, 2], [0, 0, 1, 3], [0, 0, 0, 1]]
4643
trans_m123 = [[1, 0, 0, -1], [0, 1, 0, -2], [0, 0, 1, -3], [0, 0, 0, 1]]
4744
rot_3 = from_matvec(euler2mat(np.pi / 4), [0, 0, 0])
48-
for in_shape, in_aff, vox, out_shape, out_aff in (
45+
return ( # in_shape, in_aff, vox, out_shape, out_aff
4946
# Identity
5047
((2, 3, 4), np.eye(4), None, (2, 3, 4), np.eye(4)),
5148
# Flip first axis
@@ -81,7 +78,16 @@ def test_vox2out_vox():
8178
# Number of voxel sizes matches length
8279
((2, 3), np.diag([4, 5, 6, 1]), (4, 5),
8380
(2, 3), np.diag([4, 5, 1, 1])),
84-
):
81+
)
82+
83+
84+
def test_vox2out_vox():
85+
# Test world space bounding box
86+
# Test basic case, identity, no voxel sizes passed
87+
shape, aff = vox2out_vox(((2, 3, 4), np.eye(4)))
88+
assert_array_equal(shape, (2, 3, 4))
89+
assert_array_equal(aff, np.eye(4))
90+
for in_shape, in_aff, vox, out_shape, out_aff in get_outspace_params():
8591
img = Nifti1Image(np.ones(in_shape), in_aff)
8692
for input in ((in_shape, in_aff), img):
8793
shape, aff = vox2out_vox(input, vox)

0 commit comments

Comments
 (0)