Skip to content

Commit 3b893c6

Browse files
committed
enh: add simple unit test
1 parent d08bc13 commit 3b893c6

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

niworkflows/utils/tests/test_images.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import numpy as np
33

44
import pytest
5-
from ..images import update_header_fields, overwrite_header
5+
from ..images import update_header_fields, overwrite_header, dseg_label
66

77

88
def random_image():
@@ -71,3 +71,18 @@ def test_overwrite_header_reject_mmap(tmp_path):
7171
img = nb.load(fname, mmap=True)
7272
with pytest.raises(ValueError):
7373
overwrite_header(img, fname)
74+
75+
76+
def test_dseg_label(tmp_path):
77+
fname = str(tmp_path / 'test_file.nii.gz')
78+
79+
data = np.dstack((
80+
np.zeros((20, 20), dtype='int16'),
81+
np.ones((20, 20), dtype='int16'),
82+
np.ones((20, 20), dtype='int16') * 2,
83+
np.ones((20, 20), dtype='int16') * 3,
84+
))
85+
nb.Nifti1Image(data, np.eye(4), None).to_filename(fname)
86+
87+
new_im = nb.load(dseg_label(fname, label=2))
88+
assert np.all((data == 2).astype('int16') == np.int16(new_im.dataobj))

0 commit comments

Comments
 (0)