diff --git a/tests/test_logging.py b/tests/test_logging.py new file mode 100644 index 0000000..4836f7a --- /dev/null +++ b/tests/test_logging.py @@ -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 diff --git a/tests/test_table.py b/tests/test_table.py index df2d60d..5a665ea 100644 --- a/tests/test_table.py +++ b/tests/test_table.py @@ -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): @@ -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(