Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nigsp/tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# ### Unit tests
def test_zerocross():
"""Text zerocross with legendre polynomials."""
"""Test zerocross with legendre polynomials."""
def _bonnet(d, x):
if(d == 0):
return np.ones_like(x)
Expand All @@ -28,7 +28,7 @@ def _bonnet(d, x):


def test_nodestrength():
"""Text nodestrength with random matrix."""
"""Test nodestrength with random matrix."""
a = np.random.rand(3, 3)
a = a - a.mean()
b = np.abs(a)
Expand Down
1 change: 1 addition & 0 deletions nigsp/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

# ### Integration tests
def test_integration(timeseries, sc_mtx, atlas, mean_fc, sdi, testdir):
"""Integration test for FULL workflow."""
testdir = join(testdir, 'testdir')
mean_fc_mat = np.genfromtxt(mean_fc)
sdi_mat = np.genfromtxt(sdi)
Expand Down
32 changes: 24 additions & 8 deletions nigsp/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,17 @@ def test_check_mtx_dim_cases(data, shape):
assert data_out.ndim == 2


def test_load_nifti_get_mask():
def test_load_nifti_get_mask(atlas):
"""Test load_nifti_get_mask."""
# #!#
pass
img = nibabel.load(atlas)
data = img.get_fdata()
mask = data.any(axis=-1).squeeze()

d, m, i = io.load_nifti_get_mask(atlas, ndim=3)

assert (data == d).all()
assert (mask == m).all()
assert (img.header['dim'] == i.header['dim']).all()


def test_load_txt():
Expand All @@ -110,6 +117,7 @@ def test_load_txt():


def test_load_mat():
"""Test load_mat."""
a = rand(5)
b = 'likealeaf'
n = 'inthewind'
Expand All @@ -122,11 +130,13 @@ def test_load_mat():
remove(n)


def test_export_nifti():
# #!# NEEDS IMAGE
# io.export_nifti(rand(3, 4, 5), img, 'book')
# assert isfile('book.nii.gz')
pass
def test_export_nifti(atlas):
"""Test export_nifti."""
img = nibabel.load(atlas)
shape = img.get_fdata().shape
io.export_nifti(empty(shape), img, 'book')
assert isfile('book.nii.gz')
remove('book.nii.gz')


@mark.parametrize('ext_in, ext_out', [
Expand Down Expand Up @@ -169,6 +179,7 @@ def test_break_check_nifti_dim(data):


def test_break_check_mtx_dim():
"""Break check_mtx_dim."""
with raises(ValueError) as errorinfo:
io.check_mtx_dim('river', empty(0))
assert 'river is empty' in str(errorinfo.value)
Expand All @@ -183,6 +194,7 @@ def test_break_check_mtx_dim():


def test_break_load_nifti_get_mask():
"""Break load_nifti_get_mask."""
sys.modules['nibabel'] = None
with raises(ImportError) as errorinfo:
io.load_nifti_get_mask('reavers')
Expand All @@ -191,6 +203,7 @@ def test_break_load_nifti_get_mask():


def test_break_load_mat():
"""Break load_mat."""
sys.modules['pymatreader'] = None
with raises(ImportError) as errorinfo:
io.load_mat('simon')
Expand All @@ -208,12 +221,14 @@ def test_break_load_mat():


def test_break_load_xls():
"""Break load_xls."""
with raises(NotImplementedError) as errorinfo:
io.load_xls('firefly')
assert 'loading is not' in str(errorinfo.value)


def test_break_export_nifti():
"""Break export_nifti."""
sys.modules['nibabel'] = None
with raises(ImportError) as errorinfo:
io.export_nifti(rand(3), None, 'reavers')
Expand All @@ -222,6 +237,7 @@ def test_break_export_nifti():


def test_break_export_mtx():
"""Break export_mtx."""
with raises(NotImplementedError) as errorinfo:
io.export_mtx(rand(3, 4), 'lostinthewoods', ext='.xls')
assert 'output is not' in str(errorinfo.value)
Expand Down