Repository: mne-tools/mne-python

Issue:
BUG: Report test failure
@mainakjas I get this error on current master:

```
======================================================================
FAIL: Test rendering -*.fif files for mne report.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/larsoner/custombuilds/mne-python/mne/tests/test_report.py", line 72, in test_render_report
    assert_true(''.join(report.html).find(op.basename(fname)) != -1)
AssertionError: False is not true
    'False is not true' = self._formatMessage('False is not true', "%s is not true" % safe_repr(False))
>>  raise self.failureException('False is not true')
```

Any ideas?



Discussion:
@Eric89GXL this is a mysterious one had it randomly a couple of times before. Can you see which exact file is not found?

`/home/larsoner/custombuilds/mne-python/mne/io/tests/data/test_ctf_comp_raw-eve.fif`

This file might get created by the forward tests (if it calls the forward wrapper), so it should probably be excluded. Or maybe instead of using `glob.glob('*.fif')` to find the files, it should explicitly list the ones that are expected...? I'm not sure what the right answer is here.

@Eric89GXL haa, I had the same one. I just deleted it to overcome the problem (since it wasn't on master). I was assuming it was some left over from last december's pre-release ctf struggles ....

Same for me

> On 24 juil. 2014, at 21:07, "Denis A. Engemann" notifications@github.com wrote:
> 
> @Eric89GXL haa, I had the same one. I just deleted it to overcome the problem (since it wasn't on master). I was assuming it was some left over from last december's pre-release ctf struggles ....
> 
> —
> Reply to this email directly or view it on GitHub.

Okay, tests pass for me now. I'll assume this is isolated to us, then.

Does the file get re-created by some test or not?

I'm going to be running and re-running tests a bit here, if it comes back up I'll re-open.

yes, we should leave the file out if it's getting created by some other test, but I had tried to grep for that filename in the repo and couldn't find it ...

I definitely have the file again. It's not in the repo, but some test creates it -- it must call one of the mne-C functions, which in turn creates the `-eve.fif` file. I'll just manually exclude it from the test.

(I have a PR coming soon anyway)

ok, thanks !


Resolving patch:
diff --git a/mne/source_estimate.py b/mne/source_estimate.py
--- a/mne/source_estimate.py
+++ b/mne/source_estimate.py
@@ -1704,11 +1704,12 @@ def get_peak(self, tmin=None, tmax=None, mode='abs',
         """
 
         vert_idx, time_idx = _get_peak(self.data, self.times, tmin, tmax,
-                                             mode)
+                                       mode)
 
         return (vert_idx if vert_as_index else self.vertno[vert_idx],
                 time_idx if time_as_index else self.times[time_idx])
 
+
 ###############################################################################
 # Morphing
 
@@ -1944,7 +1945,6 @@ def _morph_sparse(stc, subject_from, subject_to, subjects_dir=None):
     return stc_morph
 
 
-
 @verbose
 def morph_data(subject_from, subject_to, stc_from, grade=5, smooth=None,
                subjects_dir=None, buffer_size=64, n_jobs=1, verbose=None):
@@ -2561,9 +2561,10 @@ def save_stc_as_volume(fname, stc, src, dest='mri', mri_resolution=False):
     header = nib.nifti1.Nifti1Header()
     header.set_xyzt_units('mm', 'msec')
     header['pixdim'][4] = 1e3 * stc.tstep
-    img = nib.Nifti1Image(vol, affine, header=header)
-    if fname is not None:
-        nib.save(img, fname)
+    with warnings.catch_warnings(record=True):  # nibabel<->numpy warning
+        img = nib.Nifti1Image(vol, affine, header=header)
+        if fname is not None:
+            nib.save(img, fname)
     return img
 
 
diff --git a/mne/viz/_3d.py b/mne/viz/_3d.py
--- a/mne/viz/_3d.py
+++ b/mne/viz/_3d.py
@@ -110,27 +110,33 @@ def plot_evoked_field(evoked, surf_maps, time=None, time_label='t = %0.0f ms',
         # Make a solid surface
         vlim = np.max(np.abs(data))
         alpha = alphas[ii]
-        mesh = mlab.pipeline.triangular_mesh_source(x, y, z, surf['tris'])
+        with warnings.catch_warnings(record=True):  # traits
+            mesh = mlab.pipeline.triangular_mesh_source(x, y, z, surf['tris'])
         mesh.data.point_data.normals = nn
         mesh.data.cell_data.normals = None
         mlab.pipeline.surface(mesh, color=colors[ii], opacity=alpha)
 
         # Now show our field pattern
-        mesh = mlab.pipeline.triangular_mesh_source(x, y, z, surf['tris'],
-                                                    scalars=data)
+        with warnings.catch_warnings(record=True):  # traits
+            mesh = mlab.pipeline.triangular_mesh_source(x, y, z, surf['tris'],
+                                                        scalars=data)
         mesh.data.point_data.normals = nn
         mesh.data.cell_data.normals = None
-        fsurf = mlab.pipeline.surface(mesh, vmin=-vlim, vmax=vlim)
+        with warnings.catch_warnings(record=True):  # traits
+            fsurf = mlab.pipeline.surface(mesh, vmin=-vlim, vmax=vlim)
         fsurf.module_manager.scalar_lut_manager.lut.table = colormap
 
         # And the field lines on top
-        mesh = mlab.pipeline.triangular_mesh_source(x, y, z, surf['tris'],
-                                                    scalars=data)
+        with warnings.catch_warnings(record=True):  # traits
+            mesh = mlab.pipeline.triangular_mesh_source(x, y, z, surf['tris'],
+                                                        scalars=data)
         mesh.data.point_data.normals = nn
         mesh.data.cell_data.normals = None
-        cont = mlab.pipeline.contour_surface(mesh, contours=21, line_width=1.0,
-                                             vmin=-vlim, vmax=vlim,
-                                             opacity=alpha)
+        with warnings.catch_warnings(record=True):  # traits
+            cont = mlab.pipeline.contour_surface(mesh, contours=21,
+                                                 line_width=1.0,
+                                                 vmin=-vlim, vmax=vlim,
+                                                 opacity=alpha)
         cont.module_manager.scalar_lut_manager.lut.table = colormap_lines
 
     if '%' in time_label:
@@ -299,7 +305,8 @@ def plot_trans(info, trans_fname='auto', subject=None, subjects_dir=None,
 
         # Make a solid surface
         alpha = alphas[ii]
-        mesh = mlab.pipeline.triangular_mesh_source(x, y, z, surf['tris'])
+        with warnings.catch_warnings(record=True):  # traits
+            mesh = mlab.pipeline.triangular_mesh_source(x, y, z, surf['tris'])
         mesh.data.point_data.normals = nn
         mesh.data.cell_data.normals = None
         mlab.pipeline.surface(mesh, color=colors[ii], opacity=alpha)
@@ -314,8 +321,9 @@ def plot_trans(info, trans_fname='auto', subject=None, subjects_dir=None,
             # Transform EEG electrodes to MRI coordinates
             eeg_loc = apply_trans(trans['trans'], eeg_loc)
 
-            mlab.points3d(eeg_loc[:, 0], eeg_loc[:, 1], eeg_loc[:, 2],
-                          color=(1.0, 0.0, 0.0), scale_factor=0.005)
+            with warnings.catch_warnings(record=True):  # traits
+                mlab.points3d(eeg_loc[:, 0], eeg_loc[:, 1], eeg_loc[:, 2],
+                              color=(1.0, 0.0, 0.0), scale_factor=0.005)
         else:
             warnings.warn('EEG electrode locations not found. '
                           'Cannot plot EEG electrodes.')
@@ -458,7 +466,8 @@ def plot_source_estimates(stc, subject=None, surface='inflated', hemi='lh',
     else:
         logger.info('PySurfer does not support "views" argument, please '
                     'consider updating to a newer version (0.4 or later)')
-    brain = Brain(subject, hemi, surface, **kwargs)
+    with warnings.catch_warnings(record=True):  # traits warnings
+        brain = Brain(subject, hemi, surface, **kwargs)
     for hemi in hemis:
         hemi_idx = 0 if hemi == 'lh' else 1
         if hemi_idx == 0:
@@ -467,10 +476,11 @@ def plot_source_estimates(stc, subject=None, surface='inflated', hemi='lh',
             data = stc.data[len(stc.vertno[0]):]
         vertices = stc.vertno[hemi_idx]
         time = 1e3 * stc.times
-        brain.add_data(data, colormap=colormap, vertices=vertices,
-                       smoothing_steps=smoothing_steps, time=time,
-                       time_label=time_label, alpha=alpha, hemi=hemi,
-                       colorbar=colorbar)
+        with warnings.catch_warnings(record=True):  # traits warnings
+            brain.add_data(data, colormap=colormap, vertices=vertices,
+                           smoothing_steps=smoothing_steps, time=time,
+                           time_label=time_label, alpha=alpha, hemi=hemi,
+                           colorbar=colorbar)
 
         # scale colormap and set time (index) to display
         brain.scale_data_colormap(fmin=fmin, fmid=fmid, fmax=fmax,
@@ -478,7 +488,6 @@ def plot_source_estimates(stc, subject=None, surface='inflated', hemi='lh',
 
     if time_viewer:
         TimeViewer(brain)
-
     return brain
 
 
@@ -576,9 +585,11 @@ def plot_sparse_source_estimates(src, stcs, colors=None, linewidth=2,
     mlab.clf()
     if mlab.options.backend != 'test':
         f.scene.disable_render = True
-    surface = mlab.triangular_mesh(points[:, 0], points[:, 1], points[:, 2],
-                                   use_faces, color=brain_color,
-                                   opacity=opacity, **kwargs)
+    with warnings.catch_warnings(record=True):  # traits warnings
+        surface = mlab.triangular_mesh(points[:, 0], points[:, 1],
+                                       points[:, 2], use_faces,
+                                       color=brain_color,
+                                       opacity=opacity, **kwargs)
 
     import matplotlib.pyplot as plt
     # Show time courses
@@ -608,13 +619,14 @@ def plot_sparse_source_estimates(src, stcs, colors=None, linewidth=2,
         scale_factor = scale_factors[1] if is_common else scale_factors[0]
 
         if (isinstance(scale_factor, (np.ndarray, list, tuple))
-             and len(unique_vertnos) == len(scale_factor)):
+                and len(unique_vertnos) == len(scale_factor)):
             scale_factor = scale_factor[idx]
 
         x, y, z = points[v]
         nx, ny, nz = normals[v]
-        mlab.quiver3d(x, y, z, nx, ny, nz, color=color_converter.to_rgb(c),
-                      mode=mode, scale_factor=scale_factor)
+        with warnings.catch_warnings(record=True):  # traits
+            mlab.quiver3d(x, y, z, nx, ny, nz, color=color_converter.to_rgb(c),
+                          mode=mode, scale_factor=scale_factor)
 
         for k in ind:
             vertno = vertnos[k]


Test patch:
diff --git a/mne/preprocessing/tests/test_ica.py b/mne/preprocessing/tests/test_ica.py
--- a/mne/preprocessing/tests/test_ica.py
+++ b/mne/preprocessing/tests/test_ica.py
@@ -128,10 +128,12 @@ def test_ica_rank_reduction():
     n_components = 5
     max_pca_components = len(picks)
     for n_pca_components in [6, 10]:
-        ica = ICA(n_components=n_components,
-                  max_pca_components=max_pca_components,
-                  n_pca_components=n_pca_components,
-                  method='fastica', max_iter=1).fit(raw, picks=picks)
+        with warnings.catch_warnings(record=True):  # non-convergence
+            warnings.simplefilter('always')
+            ica = ICA(n_components=n_components,
+                      max_pca_components=max_pca_components,
+                      n_pca_components=n_pca_components,
+                      method='fastica', max_iter=1).fit(raw, picks=picks)
 
         rank_before = raw.estimate_rank(picks=picks)
         assert_equal(rank_before, len(picks))
@@ -186,7 +188,7 @@ def test_ica_core():
         # test decomposition
         with warnings.catch_warnings(record=True):
             ica.fit(raw, picks=pcks, start=start, stop=stop)
-            _ = repr(ica)  # to test repr
+            repr(ica)  # to test repr
 
         # test re-fit
         unmixing1 = ica.unmixing_matrix_
@@ -412,7 +414,8 @@ def test_ica_additional():
         assert_equal(len(scores), ica.n_components_)
         assert_raises(ValueError, ica.find_bads_ecg, epochs.average(),
                       method='ctps')
-        assert_raises(ValueError, ica.find_bads_ecg, raw, method='crazy-coupling')
+        assert_raises(ValueError, ica.find_bads_ecg, raw,
+                      method='crazy-coupling')
 
         idx, scores = ica.find_bads_eog(raw)
         assert_equal(len(scores), ica.n_components_)
@@ -513,7 +516,7 @@ def test_ica_reject_buffer():
     set_log_file(drop_log, overwrite=True)
     with warnings.catch_warnings(record=True):
         ica.fit(raw, picks[:5], reject=dict(mag=2.5e-12), decim=2,
-            tstep=0.01, verbose=True)
+                tstep=0.01, verbose=True)
     assert_true(raw._data[:5, ::2].shape[1] - 4 == ica.n_samples_)
     with open(drop_log) as fid:
         log = [l for l in fid if 'detected' in l]
diff --git a/mne/stats/tests/test_regression.py b/mne/stats/tests/test_regression.py
--- a/mne/stats/tests/test_regression.py
+++ b/mne/stats/tests/test_regression.py
@@ -58,7 +58,8 @@ def test_regression():
     stc = read_source_estimate(stc_fname).crop(0, 0.02)
     stc_list = [stc, stc, stc]
     stc_gen = (s for s in stc_list)
-    lm1 = linear_regression(stc_list, design_matrix[:len(stc_list)])
+    with warnings.catch_warnings(record=True):  # divide by zero
+        lm1 = linear_regression(stc_list, design_matrix[:len(stc_list)])
     lm2 = linear_regression(stc_gen, design_matrix[:len(stc_list)])
 
     for k in lm1:
diff --git a/mne/tests/test_report.py b/mne/tests/test_report.py
--- a/mne/tests/test_report.py
+++ b/mne/tests/test_report.py
@@ -62,11 +62,15 @@ def test_render_report():
 
     # Check if all files were rendered in the report
     fnames = glob.glob(op.join(base_dir, '*.fif'))
+    bad_name = 'test_ctf_comp_raw-eve.fif'
+    decrement = any(fname.endswith(bad_name) for fname in fnames)
     fnames = [fname for fname in fnames if
               fname.endswith(('-eve.fif', '-ave.fif', '-cov.fif',
                               '-sol.fif', '-fwd.fif', '-inv.fif',
                               '-src.fif', '-trans.fif', 'raw.fif',
-                              'sss.fif', '-epo.fif'))]
+                              'sss.fif', '-epo.fif')) and
+              not fname.endswith(bad_name)]
+    # last file above gets created by another test, and it shouldn't be there
 
     for fname in fnames:
         assert_true(''.join(report.html).find(op.basename(fname)) != -1)
@@ -77,7 +81,7 @@ def test_render_report():
     evoked1 = read_evokeds(evoked1_fname)
     evoked2 = read_evokeds(evoked2_fname)
     assert_equal(len(report.fnames) + len(evoked1) + len(evoked2) - 2,
-                 report.initial_id)
+                 report.initial_id - decrement)
 
     # Check saving functionality
     report.data_path = tempdir
diff --git a/mne/tests/test_source_estimate.py b/mne/tests/test_source_estimate.py
--- a/mne/tests/test_source_estimate.py
+++ b/mne/tests/test_source_estimate.py
@@ -59,6 +59,7 @@ def test_volume_stc():
             assert_true(isinstance(stc_new, VolSourceEstimate))
             assert_array_equal(vertno_read, stc_new.vertno)
             assert_array_almost_equal(stc.data, stc_new.data)
+
     # now let's actually read a MNE-C processed file
     stc = read_source_estimate(fname_vol, 'sample')
     assert_true(isinstance(stc, VolSourceEstimate))
@@ -83,13 +84,16 @@ def test_volume_stc():
         vol_fname = op.join(tempdir, 'stc.nii.gz')
         stc.save_as_volume(vol_fname, src,
                            dest='surf', mri_resolution=False)
-        img = nib.load(vol_fname)
+        with warnings.catch_warnings(record=True):  # nib<->numpy
+            img = nib.load(vol_fname)
         assert_true(img.shape == src[0]['shape'] + (len(stc.times),))
 
-        t1_img = nib.load(fname_t1)
+        with warnings.catch_warnings(record=True):  # nib<->numpy
+            t1_img = nib.load(fname_t1)
         stc.save_as_volume(op.join(tempdir, 'stc.nii.gz'), src,
                            dest='mri', mri_resolution=True)
-        img = nib.load(vol_fname)
+        with warnings.catch_warnings(record=True):  # nib<->numpy
+            img = nib.load(vol_fname)
         assert_true(img.shape == t1_img.shape + (len(stc.times),))
         assert_array_almost_equal(img.get_affine(), t1_img.get_affine(),
                                   decimal=5)
@@ -580,7 +584,8 @@ def test_as_data_frame():
                         if isinstance(ind, list) else [ind])
             assert_array_equal(df.values.T[ncat:], stc.data)
             # test that non-indexed data were present as categorial variables
-            df.reset_index().columns[:3] == ['subject', 'time']
+            with warnings.catch_warnings(record=True):  # pandas
+                df.reset_index().columns[:3] == ['subject', 'time']
 
 
 def test_get_peak():
diff --git a/mne/viz/tests/test_ica.py b/mne/viz/tests/test_ica.py
--- a/mne/viz/tests/test_ica.py
+++ b/mne/viz/tests/test_ica.py
@@ -7,7 +7,6 @@
 from functools import wraps
 import warnings
 
-import numpy as np
 from numpy.testing import assert_raises
 
 from mne import io, read_events, Epochs, read_cov
@@ -103,7 +102,8 @@ def test_plot_ica_sources():
     ica.fit(raw, picks=ica_picks)
     ica.plot_sources(raw)
     ica.plot_sources(epochs)
-    ica.plot_sources(epochs.average())
+    with warnings.catch_warnings(record=True):  # no labeled objects mpl
+        ica.plot_sources(epochs.average())
     assert_raises(ValueError, ica.plot_sources, 'meeow')
     plt.close('all')