Skip to content

Commit

Permalink
MAINT: Better test fixtures (mne-tools#7358)
Browse files Browse the repository at this point in the history
* WIP: Try to fix PySurfer failures

* FIX: Try fixing Mayavi

* ENH: Speed up failure (hopefully)

* FIX: Try again

* FIX: Try another

* FIX: Better testing

* FIX: MPL version
  • Loading branch information
larsoner authored and AdoNunes committed Apr 6, 2020
1 parent 7dff304 commit ae1f6e8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
25 changes: 24 additions & 1 deletion mne/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#
# License: BSD (3-clause)

from distutils.version import LooseVersion
import gc
import os
import os.path as op
import shutil
Expand Down Expand Up @@ -79,6 +81,7 @@ def pytest_configure(config):
ignore:The sklearn.*module.*deprecated.*:FutureWarning
ignore:.*TraitTuple.*trait.*handler.*deprecated.*:DeprecationWarning
ignore:.*rich_compare.*metadata.*deprecated.*:DeprecationWarning
ignore:.*In future, it will be an error for 'np.bool_'.*:DeprecationWarning
always:.*get_data.* is deprecated in favor of.*:DeprecationWarning
""" # noqa: E501
for warning_line in warning_lines.split('\n'):
Expand All @@ -91,6 +94,7 @@ def pytest_configure(config):
def matplotlib_config():
"""Configure matplotlib for viz tests."""
import matplotlib
from matplotlib import cbook
# "force" should not really be necessary but should not hurt
kwargs = dict()
with warnings.catch_warnings(record=True): # ignore warning
Expand All @@ -110,6 +114,18 @@ def matplotlib_config():
else:
ETSConfig.toolkit = 'qt4'

# Make sure that we always reraise exceptions in handlers
orig = cbook.CallbackRegistry

class CallbackRegistryReraise(orig):
def __init__(self, exception_handler=None):
args = ()
if LooseVersion(matplotlib.__version__) >= LooseVersion('2.1'):
args += (exception_handler,)
super(CallbackRegistryReraise, self).__init__(*args)

cbook.CallbackRegistry = CallbackRegistryReraise


@pytest.fixture()
def check_gui_ci():
Expand Down Expand Up @@ -201,7 +217,7 @@ def backend_name(request):


@pytest.yield_fixture
def renderer(backend_name):
def renderer(backend_name, garbage_collect):
"""Yield the 3D backends."""
from mne.viz.backends.renderer import _use_test_3d_backend
_check_skip_backend(backend_name)
Expand All @@ -211,6 +227,13 @@ def renderer(backend_name):
renderer._close_all()


@pytest.yield_fixture
def garbage_collect():
"""Garbage collect on exit."""
yield
gc.collect()


@pytest.fixture(scope="module", params=[
"pyvista",
])
Expand Down
5 changes: 3 additions & 2 deletions mne/io/nirx/nirx.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ def __init__(self, fname, preload=False, verbose=None):

# Read number of rows/samples of wavelength data
last_sample = -1
for line in _open(files['wl1']):
last_sample += 1
with _open(files['wl1']) as fid:
for line in fid:
last_sample += 1

# Read participant information file
inf = ConfigParser(allow_no_value=True)
Expand Down
4 changes: 2 additions & 2 deletions mne/viz/tests/test_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ def test_plot_volume_source_estimates_morph():
@requires_pysurfer
@requires_mayavi
@traits_test
def test_plot_vector_source_estimates():
def test_plot_vector_source_estimates(garbage_collect):
"""Test plotting of vector source estimates."""
sample_src = read_source_spaces(src_fname)

Expand Down Expand Up @@ -721,7 +721,7 @@ def test_brain_colorbar(orientation, diverging, lims):
@requires_pysurfer
@testing.requires_testing_data
@traits_test
def test_mixed_sources_plot_surface():
def test_mixed_sources_plot_surface(garbage_collect):
"""Test plot_surface() for mixed source space."""
src = read_source_spaces(fwd_fname2)
N = np.sum([s['nuse'] for s in src]) # number of sources
Expand Down
2 changes: 1 addition & 1 deletion mne/viz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,7 @@ def key_press(self, event):
elif self.index >= len(self.cycle):
self.index = 0
cmap = self.cycle[self.index]
self.cbar.set_cmap(cmap)
self.cbar.mappable.set_cmap(cmap)
self.cbar.draw_all()
self.mappable.set_cmap(cmap)
self.mappable.set_norm(self.cbar.norm)
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
numpy
scipy
matplotlib
mayavi
pyqt5!=5.14.1
pyqt5-sip
sip
Expand All @@ -23,11 +22,12 @@ joblib
psutil
dipy
https://api.github.com/repos/numpy/numpydoc/zipball/master
mayavi
PySurfer[save_movie]
nilearn
neo
xlrd
pydocstyle
flake8
https://github.com/mcmtroffaes/sphinxcontrib-bibtex/zipball/29694f215b39d64a31b845aafd9ff2ae9329494f
https://api.github.com/repos/mcmtroffaes/sphinxcontrib-bibtex/zipball/29694f215b39d64a31b845aafd9ff2ae9329494f
pyvista>=0.23.1

0 comments on commit ae1f6e8

Please sign in to comment.