Skip to content

Commit 882aaa3

Browse files
committed
test: Verify that dotfiles are ignored by default and with custom ignores
1 parent 76b34b8 commit 882aaa3

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/bids/layout/tests/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from os.path import join
2+
import shutil
23

34
import pytest
45

@@ -101,3 +102,10 @@ def layout_synthetic(tests_dir, request, db_dir):
101102
def layout_synthetic_nodb(tests_dir, request, db_dir):
102103
path = tests_dir / 'data' / 'synthetic'
103104
return BIDSLayout(path, derivatives=True)
105+
106+
107+
@pytest.fixture
108+
def temporary_dataset(tmp_path, tests_dir):
109+
path = tests_dir / 'data' / 'ds005'
110+
shutil.copytree(path, tmp_path / 'ds005')
111+
return tmp_path / 'ds005'

src/bids/layout/tests/test_layout.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,3 +1170,28 @@ def test_symlinks_in_path(tests_dir, tmp_path):
11701170
os.symlink(src_sub, link_sub)
11711171

11721172
assert "Subjects: 1 | Sessions: 2 | Runs: 2" in str(BIDSLayout(tmp_path / "7t_trt"))
1173+
1174+
1175+
def test_ignore_dotfiles(temporary_dataset):
1176+
arbitrary_dotfile = temporary_dataset / '.dotfile'
1177+
ds_store = temporary_dataset / 'sub-01' / '.DS_Store'
1178+
osx_companion_file = temporary_dataset / '._task-mixedgamblestask_bold.json'
1179+
1180+
arbitrary_dotfile.touch()
1181+
ds_store.touch()
1182+
osx_companion_file.touch()
1183+
1184+
# Default behavior
1185+
layout = BIDSLayout(temporary_dataset, validate=False)
1186+
assert str(temporary_dataset / 'dataset_description.json') in layout.files
1187+
assert str(arbitrary_dotfile) not in layout.files
1188+
assert str(ds_store) not in layout.files
1189+
assert str(osx_companion_file) not in layout.files
1190+
1191+
# Explicit ignores do not disable dotfile filtering
1192+
indexer = BIDSLayoutIndexer(ignore=['some_ignore'])
1193+
layout = BIDSLayout(temporary_dataset, validate=False, indexer=indexer)
1194+
assert str(temporary_dataset / 'dataset_description.json') in layout.files
1195+
assert str(arbitrary_dotfile) not in layout.files
1196+
assert str(ds_store) not in layout.files
1197+
assert str(osx_companion_file) not in layout.files

0 commit comments

Comments
 (0)