Skip to content

Commit

Permalink
Fix non-deterministic BIDS table file order in test_table (#29)
Browse files Browse the repository at this point in the history
* Fix non-deterministic BIDS table file order

Fix non-deterministic BIDS table file order and add more asserts to
check the expected fields.

* Add test for `setup_logging`
  • Loading branch information
clane9 authored May 1, 2024
1 parent c3f4c12 commit bf7c302
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
20 changes: 20 additions & 0 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import logging
from pathlib import Path

from bids2table.logging import setup_logging


def test_setup_logging(tmp_path: Path):
log_path = tmp_path / "log.txt"
logger = setup_logging(
level=logging.INFO,
log_path=tmp_path / "log.txt",
max_repeats=5,
overwrite=True,
)

for ii in range(0, 10):
logger.info(f"log msg {ii}")

log = log_path.read_text().strip().split("\n")
assert len(log) == 6
19 changes: 16 additions & 3 deletions tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

@pytest.fixture(scope="module")
def tab() -> BIDSTable:
return bids2table(BIDS_EXAMPLES / "ds001")
tab = bids2table(BIDS_EXAMPLES / "ds001")
# sort rows to get deterministic order
tab = tab.sort_values("finfo__file_path", ignore_index=True)
return tab


def test_table(tab: BIDSTable):
Expand Down Expand Up @@ -45,10 +48,20 @@ def test_table_files(tab: BIDSTable):
files = tab.files
assert len(files) == 128

file = files[0]
file = files[2]
assert file.dataset == "ds001"

assert file.path.exists()
assert (file.root / file.relative_path).exists()
assert file.metadata == {}

assert file.path.name == "sub-01_task-balloonanalogrisktask_run-01_bold.nii.gz"
assert file.metadata == {
"RepetitionTime": 2.0,
"TaskName": "balloon analog risk task",
}

ents = file.entities
assert (ents.sub, ents.task, ents.run) == ("01", "balloonanalogrisktask", 1)


@pytest.mark.parametrize(
Expand Down

0 comments on commit bf7c302

Please sign in to comment.