Repository: nipy/nipype

Issue:
[BUG] STDOUT of CommandLine is stored as one letter per line
### Summary
`STDOUT` from `CommandLine` interface is stored as one **letter** per line in `Terminal output` section of `_report/report.rst`

### Actual behavior
```
T
h
i
s
i
s
m
y
o
u
t
p
u
t
```
### Expected behavior

`This is my output`


### How to replicate the behavior
```bash
cd /tmp
# save test.py and test2.py
export PYTHONPATH=/tmp
python test2.py
vim /tmp/stdoutError/list_content/_report/report.rst
```

### Script/Workflow details

<details><summary>test.py</summary>
<p>

```python
#!/usr/bin/env python

from nipype.interfaces.base import CommandLine, CommandLineInputSpec, TraitedSpec, Str

# ==================
class LsInputSpec(CommandLineInputSpec):
    in_path= Str(argstr='%s')


class LsOutputSpec(TraitedSpec):
    pass

class Ls(CommandLine):
    _cmd = 'ls'
    input_spec = LsInputSpec
    output_spec = LsOutputSpec

    def _list_outputs(self):
        pass

```
</p>
</details>

<details><summary>test2.py</summary>
<p>

```python

from nipype import Node, Workflow, SelectFiles
from test import Ls

# ==================
parent_directory= '/tmp/'

# ===============
templates= {'path': '/tmp/'}
select_files= Node(SelectFiles(templates), name= 'select_files')

# ===============
stdoutError= Workflow(name='stdoutError', base_dir= parent_directory)

ls_node= Node(Ls(), name='list_content')

stdoutError.connect(select_files, 'path', ls_node, 'in_path')
stdoutError.run()
```
</p>
</details>

### Platform details:

<!-- Please run the following code from your shell and place the output between the triple ticks, below.
python -c "import nipype; from pprint import pprint; pprint(nipype.get_info())"
-->

```
191119-20:05:34,389 nipype.utils INFO:
         Running nipype version 1.2.3 (latest: 1.3.1)
{'commit_hash': 'a485cf60f',
 'commit_source': 'installation',
 'networkx_version': '2.2',
 'nibabel_version': '2.3.0',
 'nipype_version': '1.2.3',
 'numpy_version': '1.16.2',
 'pkg_path': '/home/tb571/miniconda3/lib/python3.6/site-packages/nipype',
 'scipy_version': '1.2.1',
 'sys_executable': '/home/tb571/miniconda3/bin/python',
 'sys_platform': 'linux',
 'sys_version': '3.6.7 | packaged by conda-forge | (default, Feb 28 2019, '
                '09:07:38) \n'
                '[GCC 7.3.0]',
 'traits_version': '4.6.0'}
```



Discussion:

Resolving patch:
diff --git a/nipype/utils/filemanip.py b/nipype/utils/filemanip.py
--- a/nipype/utils/filemanip.py
+++ b/nipype/utils/filemanip.py
@@ -736,7 +736,7 @@ def write_rst_header(header, level=0):
 
 def write_rst_list(items, prefix=""):
     out = []
-    for item in items:
+    for item in ensure_list(items):
         out.append("{} {}".format(prefix, str(item)))
     return "\n".join(out) + "\n\n"
 


Test patch:
diff --git a/nipype/utils/tests/test_filemanip.py b/nipype/utils/tests/test_filemanip.py
--- a/nipype/utils/tests/test_filemanip.py
+++ b/nipype/utils/tests/test_filemanip.py
@@ -30,6 +30,7 @@
     loadcrash,
     savepkl,
     path_resolve,
+    write_rst_list,
 )
 
 
@@ -652,3 +653,17 @@ def test_pickle(tmp_path, save_versioning):
     savepkl(pickle_fname, testobj, versioning=save_versioning)
     outobj = loadpkl(pickle_fname)
     assert outobj == testobj
+
+
+@pytest.mark.parametrize("items,expected", [
+    ('', ' \n\n'),
+    ('A string', ' A string\n\n'),
+    (['A list', 'Of strings'], ' A list\n Of strings\n\n'),
+    (None, TypeError),
+])
+def test_write_rst_list(tmp_path, items, expected):
+    if items is not None:
+        assert write_rst_list(items) == expected
+    else:
+        with pytest.raises(expected):
+            write_rst_list(items)