TEST: Verify that using 1, "1" or "01" retrieves and reconstructs run-01
@@ -14,6 +14,7 @@ import pytest
from bids.layout import BIDSLayout, Query
from bids.layout.models import Config
from bids.layout.index import BIDSLayoutIndexer
+from bids.layout.utils import PaddedInt
from bids.tests import get_test_data_path
from bids.utils import natural_sort
@@ -711,7 +712,7 @@ def test_get_with_wrong_dtypes(layout_7t_trt):
''' Test automatic dtype sanitization. '''
l = layout_7t_trt
assert (l.get(run=1) == l.get(run='1') == l.get(run=np.int64(1)) ==
- l.get(run=[1, '15']))
+ l.get(run=[1, '15']) == l.get(run='01'))
assert not l.get(run='not_numeric')
assert l.get(session=1) == l.get(session='1')
@@ -808,3 +809,16 @@ def test_load_layout_config_not_overwritten(layout_synthetic_nodb, tmpdir):
assert getattr(cm1.layout_info, attr) == getattr(cm2.layout_info, attr)
assert cm1.layout_info.config != cm2.layout_info.config
+
+
+def test_padded_run_roundtrip(layout_ds005):
+ for run in (1, "1", "01"):
+ res = layout_ds005.get(subject="01", task="mixedgamblestask",
+ run=run, extension=".nii.gz")
+ assert len(res) == 1
+ boldfile = res[0]
+ ents = boldfile.get_entities()
+ assert isinstance(ents["run"], PaddedInt)
+ assert ents["run"] == 1
+ newpath = layout_ds005.build_path(ents, absolute_paths=False)
+ assert newpath == "sub-01/func/sub-01_task-mixedgamblestask_run-01_bold.nii.gz"
