def test_config_init_from_class_load_derivatives(): config = Config.load('derivatives') assert config.name == 'derivatives' ent_names = ('space', 'atlas', 'roi') assert all([en in config.entities for en in ent_names]) assert 'subject' not in config.entities assert config.default_path_patterns is None
def test_parse_file_entities(): filename = '/sub-03_ses-07_run-4_desc-bleargh_sekret.nii.gz' # Test with entities taken from bids config target = {'subject': '03', 'session': '07', 'run': 4, 'suffix': 'sekret'} assert target == parse_file_entities(filename, config='bids') config = Config.load('bids') assert target == parse_file_entities(filename, config=[config]) # Test with entities taken from bids and derivatives config target = { 'subject': '03', 'session': '07', 'run': 4, 'suffix': 'sekret', 'desc': 'bleargh' } assert target == parse_file_entities(filename) assert target == parse_file_entities(filename, config=['bids', 'derivatives']) # Test with list of Entities entities = [ Entity('subject', "[/\\\\]sub-([a-zA-Z0-9]+)"), Entity('run', "[_/\\\\]run-0*(\\d+)", dtype=int), Entity('suffix', "[._]*([a-zA-Z0-9]*?)\\.[^/\\\\]+$"), Entity('desc', "desc-([a-zA-Z0-9]+)"), ] # Leave out session to distinguish from previous test target target = {'subject': '03', 'run': 4, 'suffix': 'sekret', 'desc': 'bleargh'} assert target == parse_file_entities(filename, entities=entities)
def test_parse_file_entities_from_layout(layout_synthetic): layout = layout_synthetic filename = '/sub-03_ses-07_run-4_desc-bleargh_sekret.nii.gz' # Test with entities taken from bids config target = {'subject': '03', 'session': '07', 'run': 4, 'suffix': 'sekret'} assert target == layout.parse_file_entities(filename, config='bids') config = Config.load('bids') assert target == layout.parse_file_entities(filename, config=[config]) assert target == layout.parse_file_entities(filename, scope='raw') # Test with default scope--i.e., everything target = { 'subject': '03', 'session': '07', 'run': 4, 'suffix': 'sekret', 'desc': 'bleargh' } assert target == layout.parse_file_entities(filename) # Test with only the fmriprep pipeline (which includes both configs) assert target == layout.parse_file_entities(filename, scope='fmriprep') assert target == layout.parse_file_entities(filename, scope='derivatives') # Test with only the derivative config target = {'desc': 'bleargh'} assert target == layout.parse_file_entities(filename, config='derivatives')
def test_parse_file_entities(): filename = '/sub-03_ses-07_run-4_desc-bleargh_sekret.nii.gz' # Test with entities taken from bids config target = {'subject': '03', 'session': '07', 'run': 4, 'suffix': 'sekret'} assert target == parse_file_entities(filename, config='bids') config = Config.load('bids') assert target == parse_file_entities(filename, config=[config]) # Test with entities taken from bids and derivatives config target = {'subject': '03', 'session': '07', 'run': 4, 'suffix': 'sekret', 'desc': 'bleargh'} assert target == parse_file_entities(filename) assert target == parse_file_entities(filename, config=['bids', 'derivatives']) # Test with list of Entities entities = [ Entity('subject', "[/\\\\]sub-([a-zA-Z0-9]+)"), Entity('run', "[_/\\\\]run-0*(\\d+)", dtype=int), Entity('suffix', "[._]*([a-zA-Z0-9]*?)\\.[^/\\\\]+$"), Entity('desc', "desc-([a-zA-Z0-9]+)"), ] # Leave out session to distinguish from previous test target target = {'subject': '03', 'run': 4, 'suffix': 'sekret', 'desc': 'bleargh'} assert target == parse_file_entities(filename, entities=entities)
def test_config_init_from_class_load_bids(): config = Config.load('bids') assert config.name == 'bids' ent_names = ('subject', 'run', 'suffix') assert all([en in config.entities for en in ent_names]) assert 'space' not in config.entities first_patt = 'sub-{subject}[/ses-{session}]/anat/sub-{subject}' assert config.default_path_patterns[0].startswith(first_patt)
def test_add_config_paths(): bids_dir = dirname(bids.__file__) bids_json = os.path.join(bids_dir, 'layout', 'config', 'bids.json') with pytest.raises(ValueError) as exc: add_config_paths(test_config1='nonexistentpath.json') assert str(exc.value).startswith('Configuration file') with pytest.raises(ValueError) as exc: add_config_paths(bids=bids_json) assert str(exc.value).startswith("Configuration 'bids' already") add_config_paths(dummy=bids_json) config = Config.load('dummy') assert 'subject' in config.entities
def test_config_init_with_args(): ents = [{ "name": "task", "pattern": "[_/\\\\]task-([a-zA-Z0-9]+)" }, { "name": "acquisition", "pattern": "[_/\\\\]acq-([a-zA-Z0-9]+)" }] patterns = ['this_will_never_match_anything', 'and_neither_will_this'] config = Config('custom', entities=ents, default_path_patterns=patterns) assert config.name == 'custom' assert {'task', 'acquisition'} == set(config.entities.keys()) assert config.default_path_patterns == patterns
def test_parse_file_entities_from_layout(layout_synthetic): layout = layout_synthetic filename = '/sub-03_ses-07_run-4_desc-bleargh_sekret.nii.gz' # Test with entities taken from bids config target = {'subject': '03', 'session': '07', 'run': 4, 'suffix': 'sekret'} assert target == layout.parse_file_entities(filename, config='bids') config = Config.load('bids') assert target == layout.parse_file_entities(filename, config=[config]) assert target == layout.parse_file_entities(filename, scope='raw') # Test with default scope--i.e., everything target = {'subject': '03', 'session': '07', 'run': 4, 'suffix': 'sekret', 'desc': 'bleargh'} assert target == layout.parse_file_entities(filename) # Test with only the fmriprep pipeline (which includes both configs) assert target == layout.parse_file_entities(filename, scope='fmriprep') assert target == layout.parse_file_entities(filename, scope='derivatives') # Test with only the derivative config target = {'desc': 'bleargh'} assert target == layout.parse_file_entities(filename, config='derivatives')
def test_config_init_bare(): config = Config('custom') assert config.name == 'custom' assert config.entities == {} assert config.default_path_patterns is None