Repository: mne-tools/mne-python

Issue:
BUG: Adding more than one figure to Report is broken
If a call to `add_figs_to_section` is made with a list of figures, only the first one is added.

In this example, only the first figure appears on the report.

``` Python
import numpy as np
import matplotlib.pyplot as plt
from mne.report import Report

r = Report('test')

fig1 = plt.figure()
plt.plot([1, 2], [1, 1])
fig2 = plt.figure()
plt.plot([1, 2], [2, 2])

r.add_figs_to_section([fig1, fig2], section='ts', captions=['fig1', 'fig2'])

r.save('test.html', overwrite=True)
```



Discussion:
Found the reason:

report.py:728

``` Python
figs, captions, comments = self._validate_input(figs, captions, section, comments)
for fig, caption, comment in zip(figs, captions, comments):
   ...
```

When `comments=None` (default), the output of `self._validate_input` is
 `([figure, figure], ['fig1', 'fig2'], [None])` 
so the `for` and `zip` only loops the first element.


Resolving patch:
diff --git a/mne/report.py b/mne/report.py
--- a/mne/report.py
+++ b/mne/report.py
@@ -554,7 +554,12 @@ def _build_html_slider(slices_range, slides_klass, slider_id):
     {{if comment is not None}}
         <br><br>
         <div style="text-align:center;">
-            {{comment}}
+            <style>
+                p.test {word-wrap: break-word;}
+            </style>
+            <p class="test">
+                {{comment}}
+            </p>
         </div>
     {{endif}}
 {{else}}
@@ -698,10 +703,16 @@ def _validate_input(self, items, captions, section, comments=None):
         if not isinstance(captions, (list, tuple)):
             captions = [captions]
         if not isinstance(comments, (list, tuple)):
-            comments = [comments]
-        if not len(items) == len(captions):
-            raise ValueError('Captions and report items must have the same'
-                             ' length.')
+            if comments is None:
+                comments = [comments] * len(captions)
+            else:
+                comments = [comments]
+        if len(comments) != len(items):
+            raise ValueError('Comments and report items must have the same '
+                             'length or comments should be None.')
+        elif len(captions) != len(items):
+            raise ValueError('Captions and report items must have the same '
+                             'length.')
 
         # Book-keeping of section names
         if section not in self.sections:


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
@@ -212,4 +212,21 @@ def test_add_htmls_to_section():
     assert_equal(html, html_compare)
 
 
+def test_validate_input():
+    report = Report()
+    items = ['a', 'b', 'c']
+    captions = ['Letter A', 'Letter B', 'Letter C']
+    section = 'ABCs'
+    comments = ['First letter of the alphabet.',
+                'Second letter of the alphabet',
+                'Third letter of the alphabet']
+    assert_raises(ValueError, report._validate_input, items, captions[:-1],
+                  section, comments=None)
+    assert_raises(ValueError, report._validate_input, items, captions, section,
+                  comments=comments[:-1])
+    values = report._validate_input(items, captions, section, comments=None)
+    items_new, captions_new, comments_new = values
+    assert_equal(len(comments_new), len(items))
+
+
 run_tests_if_main()