def test_fetch_atlas_aal(tmp_path, request_mocker): ho_dir = str(tmp_path / 'aal_SPM12' / 'aal' / 'atlas') os.makedirs(ho_dir) with open(os.path.join(ho_dir, 'AAL.xml'), 'w') as xml_file: xml_file.write("<?xml version='1.0' encoding='us-ascii'?> " "<metadata>" "</metadata>") dataset = atlas.fetch_atlas_aal(data_dir=str(tmp_path), verbose=0) assert isinstance(dataset.maps, _basestring) assert isinstance(dataset.labels, list) assert isinstance(dataset.indices, list) assert len(tst.mock_url_request.urls) == 1 with pytest.raises(ValueError, match='The version of AAL requested "FLS33"'): atlas.fetch_atlas_aal(version="FLS33", data_dir=str(tmp_path), verbose=0) assert dataset.description != ''
def test_fetch_atlas_aal(tmp_path, request_mocker): metadata = (b"<?xml version='1.0' encoding='us-ascii'?>" b"<metadata></metadata>") archive_root = Path("aal", "atlas") aal_data = dict_to_archive({ archive_root / "AAL.xml": metadata, archive_root / "AAL.nii": "" }) request_mocker.url_mapping["*AAL_files*"] = aal_data dataset = atlas.fetch_atlas_aal(data_dir=tmp_path, verbose=0) assert isinstance(dataset.maps, str) assert isinstance(dataset.labels, list) assert isinstance(dataset.indices, list) assert request_mocker.url_count == 1 with pytest.raises(ValueError, match='The version of AAL requested "FLS33"'): atlas.fetch_atlas_aal(version="FLS33", data_dir=tmp_path, verbose=0) assert dataset.description != ''
def test_fetch_atlas_aal(): ho_dir = os.path.join(tst.tmpdir, 'aal_SPM12', 'aal', 'atlas') os.makedirs(ho_dir) with open(os.path.join(ho_dir, 'AAL.xml'), 'w') as xml_file: xml_file.write("<?xml version='1.0' encoding='us-ascii'?> " "<metadata>" "</metadata>") dataset = atlas.fetch_atlas_aal(data_dir=tst.tmpdir, verbose=0) assert_true(isinstance(dataset.regions, _basestring)) assert_true(isinstance(dataset.labels, dict)) assert_equal(len(tst.mock_url_request.urls), 1) assert_raises_regex(ValueError, 'The version of AAL requested "FLS33"', atlas.fetch_atlas_aal, version="FLS33", data_dir=tst.tmpdir, verbose=0) assert_not_equal(dataset.description, '')
def test_fetch_atlas_aal(): ho_dir = os.path.join(tst.tmpdir, 'aal_SPM12', 'aal', 'atlas') os.makedirs(ho_dir) with open(os.path.join(ho_dir, 'AAL.xml'), 'w') as xml_file: xml_file.write("<?xml version='1.0' encoding='us-ascii'?> " "<metadata>" "</metadata>") dataset = atlas.fetch_atlas_aal(data_dir=tst.tmpdir, verbose=0) assert_true(isinstance(dataset.regions, _basestring)) assert_true(isinstance(dataset.labels, dict)) assert_equal(len(tst.mock_url_request.urls), 1) assert_raises_regex(ValueError, 'The version of AAL requested "FLS33"', atlas.fetch_atlas_aal, version="FLS33", data_dir=tst.tmpdir, verbose=0) assert_not_equal(dataset.description, '')
def test_fetch_atlas_aal(version, archive_format, url_key, aal_archive_root, tmp_path, request_mocker): metadata = "A\tB\tC\n" if version == 'SPM12': metadata = (b"<?xml version='1.0' encoding='us-ascii'?>" b"<metadata><label><index>1</index>" b"<name>A</name></label></metadata>") label_file = "AAL.xml" if version == 'SPM12' else "ROI_MNI_V4.txt" atlas_file = "AAL.nii" if version == 'SPM12' else "ROI_MNI_V4.nii" aal_data = dict_to_archive( {aal_archive_root / label_file: metadata, aal_archive_root / atlas_file: ""}, archive_format=archive_format ) request_mocker.url_mapping[f"*{url_key}*"] = aal_data dataset = atlas.fetch_atlas_aal( version=version, data_dir=tmp_path, verbose=0 ) assert isinstance(dataset.maps, str) assert isinstance(dataset.labels, list) assert isinstance(dataset.indices, list) assert request_mocker.url_count == 1 assert dataset.description != ''
def test_fetch_atlas_aal_version_error(tmp_path, request_mocker): with pytest.raises(ValueError, match='The version of AAL requested "FLS33"'): atlas.fetch_atlas_aal( version="FLS33", data_dir=tmp_path, verbose=0 )