Repository: mne-tools/mne-python

Issue:
report does not work for toy example
If I do this on master:

```py
from mne import Report
import matplotlib.pyplot as plt
rep = Report()
fig = plt.plot([1, 2], [1, 2])
rep.add_figs_to_section(fig, 'my caption')
```
it fails with the following message:

```py
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-a4d487ddeb86> in <module>()
      3 rep = Report()
      4 fig = plt.plot([1, 2], [1, 2])
----> 5 rep.add_figs_to_section(fig, 'my caption')

~/Desktop/projects/github_repos/mne-python/mne/report.py in add_figs_to_section(self, figs, captions, section, scale, image_format, comments, replace)
   1078             img_klass = self._sectionvars[section]
   1079 
-> 1080             img = _fig_to_img(fig, image_format, scale)
   1081             html = image_template.substitute(img=img, id=global_id,
   1082                                              div_klass=div_klass,

~/Desktop/projects/github_repos/mne-python/mne/report.py in _fig_to_img(fig, image_format, scale, **kwargs)
     74                  '`mayavi.core.api.Scene` figure instances'
     75                  ' will throw an error.' % (e,))
---> 76         if fig.scene is not None:
     77             img = mlab.screenshot(figure=fig)
     78         else:  # Testing mode

AttributeError: 'Line2D' object has no attribute 'scene'
```


Discussion:
oups @GuillaumeFavelier we broke something :(

can you have a look? or maybe @jasmainak you can find the fix quickly?
sorry it's a false alarm, plt.plot() does not return a figure object. 

Nothing to worry :-) 
It should raise an error if not a mpl or mayavi figure

Resolving patch:
diff --git a/mne/report.py b/mne/report.py
--- a/mne/report.py
+++ b/mne/report.py
@@ -69,10 +69,15 @@ def _fig_to_img(fig, image_format='png', scale=None, **kwargs):
         try:
             mlab = _import_mlab()
         # on some systems importing Mayavi raises SystemExit (!)
-        except Exception as e:
-            warn('Could not import mayavi (%r). Trying to render'
-                 '`mayavi.core.api.Scene` figure instances'
-                 ' will throw an error.' % (e,))
+        except Exception:
+            is_mayavi = False
+        else:
+            import mayavi
+            is_mayavi = isinstance(fig, mayavi.core.scene.Scene)
+        if not is_mayavi:
+            raise TypeError('Each fig must be a matplotlib Figure, mayavi '
+                            'Scene, or NumPy ndarray, got %s (type %s)'
+                            % (fig, type(fig)))
         if fig.scene is not None:
             img = mlab.screenshot(figure=fig)
         else:  # Testing mode


Test patch:
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
@@ -142,6 +142,11 @@ def test_render_report():
     # ndarray support smoke test
     report.add_figs_to_section(np.zeros((2, 3, 3)), 'caption', 'section')
 
+    with pytest.raises(TypeError, match='Each fig must be a'):
+        report.add_figs_to_section('foo', 'caption', 'section')
+    with pytest.raises(TypeError, match='Each fig must be a'):
+        report.add_figs_to_section(['foo'], 'caption', 'section')
+
 
 @testing.requires_testing_data
 def test_report_raw_psd_and_date():