def test_fetch_neurovault(): with _TestTemporaryDirectory() as temp_dir: # check that nothing is downloaded in offline mode data = neurovault.fetch_neurovault(mode='offline', data_dir=temp_dir) assert_equal(len(data.images), 0) # try to download an image data = neurovault.fetch_neurovault(max_images=1, fetch_neurosynth_words=True, mode='overwrite', data_dir=temp_dir) # specifying a filter while leaving the default term # filters in place should raise a warning. assert_warns(UserWarning, neurovault.fetch_neurovault, image_filter=lambda x: True, max_images=1, mode='offline') # if neurovault was available one image matching # default filters should have been downloaded if data.images: assert_equal(len(data.images), 1) meta = data.images_meta[0] assert_false(meta['not_mni']) assert_true(meta['is_valid']) assert_false(meta['not_mni']) assert_false(meta['is_thresholded']) assert_false( meta['map_type'] in ['ROI/mask', 'anatomical', 'parcellation']) assert_false(meta['image_type'] == 'atlas') # using a data directory we can't write into should raise a # warning unless mode is 'offline' os.chmod(temp_dir, stat.S_IREAD | stat.S_IEXEC) os.chmod(os.path.join(temp_dir, 'neurovault'), stat.S_IREAD | stat.S_IEXEC) if os.access(os.path.join(temp_dir, 'neurovault'), os.W_OK): return assert_warns(UserWarning, neurovault.fetch_neurovault, data_dir=temp_dir)
def test_fetch_neurovault(tmp_path): # check that nothing is downloaded in offline mode data = neurovault.fetch_neurovault(mode='offline', data_dir=str(tmp_path)) assert len(data.images) == 0 # try to download an image data = neurovault.fetch_neurovault(max_images=11, fetch_neurosynth_words=True, mode='overwrite', data_dir=str(tmp_path)) # specifying a filter while leaving the default term # filters in place should raise a warning. with pytest.warns(UserWarning): neurovault.fetch_neurovault(image_filter=lambda x: True, max_images=1, mode='offline') assert data.images assert len(data.images) == 11 for meta in data.images_meta: assert not meta['not_mni'] assert not meta['is_thresholded'] assert not meta['map_type'] in [ 'ROI/mask', 'anatomical', 'parcellation' ] assert not meta['image_type'] == 'atlas' # using a data directory we can't write into should raise a # warning unless mode is 'offline' os.chmod(str(tmp_path), stat.S_IREAD | stat.S_IEXEC) os.chmod(os.path.join(str(tmp_path), 'neurovault'), stat.S_IREAD | stat.S_IEXEC) if os.access(os.path.join(str(tmp_path), 'neurovault'), os.W_OK): return with pytest.warns(UserWarning): neurovault.fetch_neurovault(data_dir=str(tmp_path))
def test_fetch_neurovault(): with _TestTemporaryDirectory() as temp_dir: # check that nothing is downloaded in offline mode data = neurovault.fetch_neurovault( mode='offline', data_dir=temp_dir) assert_equal(len(data.images), 0) # try to download an image data = neurovault.fetch_neurovault( max_images=1, fetch_neurosynth_words=True, mode='overwrite', data_dir=temp_dir) # specifying a filter while leaving the default term # filters in place should raise a warning. assert_warns(UserWarning, neurovault.fetch_neurovault, image_filter=lambda x: True, max_images=1, mode='offline') # if neurovault was available one image matching # default filters should have been downloaded if data.images: assert_equal(len(data.images), 1) meta = data.images_meta[0] assert_false(meta['not_mni']) assert_true(meta['is_valid']) assert_false(meta['not_mni']) assert_false(meta['is_thresholded']) assert_false(meta['map_type'] in [ 'ROI/mask', 'anatomical', 'parcellation']) assert_false(meta['image_type'] == 'atlas') # using a data directory we can't write into should raise a # warning unless mode is 'offline' os.chmod(temp_dir, stat.S_IREAD | stat.S_IEXEC) os.chmod(os.path.join(temp_dir, 'neurovault'), stat.S_IREAD | stat.S_IEXEC) if os.access(os.path.join(temp_dir, 'neurovault'), os.W_OK): return assert_warns(UserWarning, neurovault.fetch_neurovault, data_dir=temp_dir)
def test_fetch_neurovault_errors(request_mocker): request_mocker.url_mapping["*"] = 500 data = neurovault.fetch_neurovault() assert len(data.images) == 0