Skip to content

Commit

Permalink
MRG: Make print_dir_tree expand ~ (#1013)
Browse files Browse the repository at this point in the history
* Make print_dir_tree expand ~

* Fix test and add changelog entry
  • Loading branch information
hoechenberger authored Jun 12, 2022
1 parent 2c1cdea commit a73fc5a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions doc/whats_new.rst
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit a73fc5a

Please sign in to comment.