Skip to content

Commit

Permalink
Fix when writing to directory that contains "tsv" in its name
Browse files Browse the repository at this point in the history
  • Loading branch information
hoechenberger committed Jul 6, 2021
1 parent 11e3efc commit 30bafee
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/whats_new.rst
Expand Up @@ -69,6 +69,7 @@ Bug fixes
- :func:`mne_bids.write_raw_bids` now works across data types with ``overwrite=True``, by `Alexandre Gramfort`_ (:gh:`791`)
- :func:`mne_bids.read_raw_bids` didn't always replace all traces of the measurement date and time stored in the raw data with the date found in `*_scans.tsv`, by `Richard Höchenberger`_ (:gh:`812`, :gh:`815`)
- :func:`mne_bids.read_raw_bids` crashed when the (optional) ``acq_time`` column was missing in ``*_scans.tsv``, by `Alexandre Gramfort`_ (:gh:`814`)
- :func:`mne_bids.write_raw_bids` doesn't crash anymore if the designated output directory contains the string ``"tsv"``, by `Richard Höchenberger`_ (:gh:`833`)

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

Expand Down
15 changes: 15 additions & 0 deletions mne_bids/tests/test_write.py
Expand Up @@ -2806,3 +2806,18 @@ def test_write_associated_emptyroom(_bids_validate, tmpdir):
.as_posix() # make test work on Windows, too
.endswith(meg_json_data['AssociatedEmptyRoom']))
assert meg_json_data['AssociatedEmptyRoom'].startswith('/')


@pytest.mark.parametrize(
'dir_name', ('tsv_test', 'json_test')
)
def test_write_raw_special_paths(tmpdir, dir_name):
"""Test writing to locations containing strings with special meaning."""
data_path = testing.data_path()
raw_fname = op.join(data_path, 'MEG', 'sample',
'sample_audvis_trunc_raw.fif')
raw = _read_raw_fif(raw_fname)

root = Path(tmpdir) / dir_name
bids_path = _bids_path.copy().update(root=root)
write_raw_bids(raw=raw, bids_path=bids_path)
4 changes: 2 additions & 2 deletions mne_bids/write.py
Expand Up @@ -1345,8 +1345,8 @@ def write_raw_bids(raw, bids_path, events_data=None,
# For the remaining files, we can use BIDSPath to alter.
readme_fname = op.join(bids_path.root, 'README')
participants_tsv_fname = op.join(bids_path.root, 'participants.tsv')
participants_json_fname = participants_tsv_fname.replace('tsv',
'json')
participants_json_fname = participants_tsv_fname.replace('.tsv',
'.json')

sidecar_path = bids_path.copy().update(suffix=bids_path.datatype,
extension='.json')
Expand Down

0 comments on commit 30bafee

Please sign in to comment.