Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MRG: Make print_dir_tree expand ~ #1013

Merged
merged 2 commits into from Jun 12, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/whats_new.rst
Expand Up @@ -52,6 +52,8 @@ Detailed list of changes

- The deprecated function ``mne_bids.mark_bad_channels`` has been removed in favor of :func:`mne_bids.mark_channels`, by `Richard Höchenberger`_ (:gh:`1009`)

- :func:`mne_bids.print_dir_tree` now raises a :py:class:`FileNotFoundError` instead of a :py:class:`ValueError` if the directory does not exist, by `Richard Höchenberger`_ (:gh:`1013`)

🛠 Requirements
^^^^^^^^^^^^^^^

Expand All @@ -68,6 +70,8 @@ Detailed list of changes

- :func:`~mne_bids.copyfiles.copyfile_brainvision` can now deal with ``.dat`` file extension, by `Dominik Welke`_ (:gh:`1008`)

- :func:`~mne_bids.print_dir_tree` now correctly expands ``~`` to the user's home directory, by `Richard Höchenberger`_ (:gh:`1013`)

:doc:`Find out what was new in previous releases <whats_new_previous_releases>`

.. include:: authors.rst
10 changes: 7 additions & 3 deletions mne_bids/path.py
Expand Up @@ -1174,9 +1174,13 @@ def print_dir_tree(folder, max_depth=None, return_str=False):
If `return_str` is ``True``, the directory tree is returned as a
string. Else, ``None`` is returned and the directory tree is printed.
"""
if not op.exists(folder):
raise ValueError('Directory does not exist: {}'.format(folder))

folder = _check_fname(
fname=folder,
overwrite='read',
must_exist=True,
name='Folder',
need_dir=True
)
max_depth = _check_max_depth(max_depth)

_validate_type(return_str, bool, 'return_str')
Expand Down
2 changes: 1 addition & 1 deletion mne_bids/tests/test_path.py
Expand Up @@ -165,7 +165,7 @@ def test_search_folder_for_text(capsys):

def test_print_dir_tree(capsys):
"""Test printing a dir tree."""
with pytest.raises(ValueError, match='Directory does not exist'):
with pytest.raises(FileNotFoundError, match='Folder does not exist'):
print_dir_tree('i_dont_exist')

# We check the testing directory
Expand Down