Skip to content

Commit b642cf8

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 0ed7ce0 commit b642cf8

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

nibabel/tests/test_spaces.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,14 @@ def assert_all_in(in_shape, in_affine, out_shape, out_affine):
3434
assert_true(np.all(out_grid < np.array(out_shape) + TINY))
3535

3636

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

0 commit comments

Comments
 (0)