Skip to content

Commit

Permalink
FIX: Eradicate nose
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Jul 23, 2024
1 parent 02a88b3 commit 3c49713
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 28 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ htmlcov/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
Expand Down
3 changes: 2 additions & 1 deletion hcp/io/file_mapping/tests/test_file_mapping.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from nose.tools import assert_equal, assert_raises
from pytest import raises as assert_raises
from numpy.testing import assert_equal

import hcp.tests.config as tconf
from hcp.io.file_mapping import get_file_paths
Expand Down
23 changes: 12 additions & 11 deletions hcp/io/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import mne
import numpy as np
from mne.utils import _TempDir
from nose.tools import assert_equal, assert_raises, assert_true
from numpy.testing import assert_equal
from pytest import raises as assert_raises
from numpy.testing import assert_array_equal

import hcp
Expand All @@ -26,7 +27,7 @@ def test_read_annot():
)
for channels in annots["channels"].values():
for chan in channels:
assert_true(chan in tconf.bti_chans)
assert chan in tconf.bti_chans

# segments
assert_equal(
Expand All @@ -46,18 +47,18 @@ def test_read_annot():
)
for components in annots["ica"].values():
if len(components) > 0:
assert_true(min(components) >= 0)
assert_true(max(components) <= 248)
assert min(components) >= 0
assert max(components) <= 248


def _basic_raw_checks(raw):
"""Helper for testing raw files"""
picks = mne.pick_types(raw.info, meg=True, ref_meg=False)
assert_equal(len(picks), 248)
ch_names = [raw.ch_names[pp] for pp in picks]
assert_true(all(ch.startswith("A") for ch in ch_names))
assert all(ch.startswith("A") for ch in ch_names)
ch_sorted = list(sorted(ch_names))
assert_true(ch_sorted != ch_names)
assert ch_sorted != ch_names
assert_equal(np.round(raw.info["sfreq"], 4), tconf.sfreq_raw)


Expand Down Expand Up @@ -109,7 +110,7 @@ def _epochs_basic_checks(epochs, annots, data_type):
assert_equal(len(epochs.ch_names), n_good)
assert_equal(round(epochs.info["sfreq"], 3), round(tconf.sfreq_preproc, 3))
assert_array_equal(np.unique(epochs.events[:, 2]), np.array([99], dtype=np.int))
assert_true(
assert (
_check_bounds(
epochs.times,
tconf.epochs_bounds[data_type],
Expand Down Expand Up @@ -178,7 +179,7 @@ def test_read_evoked():
n_chans += 4
n_chans -= len(set(sum([an["channels"]["all"] for an in all_annots], [])))
assert_equal(n_chans, len(evokeds[0].ch_names))
assert_true(_check_bounds(evokeds[0].times, tconf.epochs_bounds[data_type]))
assert _check_bounds(evokeds[0].times, tconf.epochs_bounds[data_type])


def test_read_info():
Expand Down Expand Up @@ -212,7 +213,7 @@ def test_read_info():
hcp_path=tempdir,
run_index=run_index,
)
assert_true(len(info["chs"]) != len(info2["chs"]))
assert len(info["chs"]) != len(info2["chs"])
common_chs = [ch for ch in info2["ch_names"] if ch in info["ch_names"]]
assert_equal(len(common_chs), len(info["chs"]))
info2 = _hcp_pick_info(info2, common_chs)
Expand All @@ -228,8 +229,8 @@ def test_read_trial_info():
trial_info = hcp.read_trial_info(
data_type=data_type, run_index=run_index, **hcp_params
)
assert_true("stim" in trial_info)
assert_true("resp" in trial_info)
assert "stim" in trial_info
assert "resp" in trial_info
assert_equal(2, len(trial_info))
for val in trial_info.values():
assert_array_equal(np.ndim(val["comments"]), 1)
Expand Down
8 changes: 2 additions & 6 deletions hcp/tests/test_anatomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import matplotlib
import mne
from nose.tools import assert_true

from hcp import compute_forward_stack, make_mne_anatomy
from hcp.tests import config as tconf
Expand All @@ -27,14 +26,14 @@ def test_anatomy():
make_mne_anatomy(
recordings_path=recordings_path, subjects_dir=subjects_dir, **hcp_params
)
assert_true(
assert (
op.isfile(
op.join(subjects_dir, hcp_params["subject"], "bem", "inner_skull.surf")
)
)
# Now we need fsaverage...
mne_subjects_dir = mne.get_config("SUBJECTS_DIR")
assert_true(mne_subjects_dir is not None)
assert mne_subjects_dir is not None
shutil.copytree(
op.join(mne_subjects_dir, "fsaverage"), op.join(subjects_dir, "fsaverage")
)
Expand All @@ -52,6 +51,3 @@ def test_anatomy():
plt.close("all")
mne.viz.plot_bem(subject=tconf.test_subject, subjects_dir=subjects_dir)
plt.close("all")


mne.utils.run_tests_if_main()
9 changes: 3 additions & 6 deletions hcp/tests/test_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import mne
import numpy as np
from nose.tools import assert_raises, assert_true
from pytest import raises as assert_raises
from numpy.testing import assert_equal

import hcp
Expand Down Expand Up @@ -68,7 +68,7 @@ def test_apply_ref_correction():
orig = raw[meg_picks[0]][0][0]
apply_ref_correction(raw)
proc = raw[meg_picks[0]][0][0]
assert_true(np.linalg.norm(orig) > np.linalg.norm(proc))
assert np.linalg.norm(orig) > np.linalg.norm(proc)


def test_map_ch_coords_to_mne():
Expand All @@ -81,7 +81,7 @@ def test_map_ch_coords_to_mne():
old_coord = evoked.info["chs"][0]["loc"]
map_ch_coords_to_mne(evoked)
new_coord = evoked.info["chs"][0]["loc"]
assert_true((old_coord != new_coord).any())
assert (old_coord != new_coord).any()


def test_interpolate_missing():
Expand All @@ -99,6 +99,3 @@ def test_interpolate_missing():
assert_equal(len(evoked.ch_names), 243)
evoked_int = interpolate_missing(evoked, data_type=data_type, **hcp_params)
assert_equal(len(evoked_int.ch_names), 248)


mne.utils.run_tests_if_main()
3 changes: 0 additions & 3 deletions hcp/tests/test_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,3 @@ def test_make_layout():
raw.pick_types()
lout = make_hcp_bti_layout(raw.info)
assert_equal(lout.names, raw.info["ch_names"])


mne.utils.run_tests_if_main()

0 comments on commit 3c49713

Please sign in to comment.