Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nipype/utils/filemanip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this ensure_list() function defined?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def ensure_list(filename):
"""Returns a list given either a string or a list
"""
if isinstance(filename, (str, bytes)):
return [filename]
elif isinstance(filename, list):
return filename
elif is_container(filename):
return [x for x in filename]
else:
return None

return "\n".join(out) + "\n\n"

Expand Down
15 changes: 15 additions & 0 deletions nipype/utils/tests/test_filemanip.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
loadcrash,
savepkl,
path_resolve,
write_rst_list,
)


Expand Down Expand Up @@ -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)