Esempio n. 1
0
def test_download_image_terms():
    with _TestTemporaryDirectory() as temp_dir:
        image_info = {'id': 'a'}
        collection = {
            'relative_path': 'collection',
            'absolute_path': os.path.join(temp_dir, 'collection')
        }
        os.makedirs(collection['absolute_path'])
        download_params = {
            'temp_dir': temp_dir,
            'verbose': 3,
            'fetch_neurosynth_words': True
        }
        with _FailingDownloads():
            neurovault._download_image_terms(image_info, collection,
                                             download_params)
            download_params['allow_neurosynth_failure'] = False
            pytest.raises(RuntimeError, neurovault._download_image_terms,
                          image_info, collection, download_params)
            with open(
                    os.path.join(collection['absolute_path'],
                                 'neurosynth_words_for_image_a.json'), 'w'):
                pass
            neurovault._download_image_terms(image_info, collection,
                                             download_params)
Esempio n. 2
0
def test_download_image_terms(request_mocker):
    with tempfile.TemporaryDirectory() as temp_dir:
        image_info = {'id': 'a'}
        collection = {
            'relative_path': 'collection',
            'absolute_path': os.path.join(temp_dir, 'collection')
        }
        os.makedirs(collection['absolute_path'])
        download_params = {
            'temp_dir': temp_dir,
            'verbose': 3,
            'fetch_neurosynth_words': True
        }
        request_mocker.url_mapping["*"] = requests.RequestException()
        neurovault._download_image_terms(image_info, collection,
                                         download_params)
        download_params['allow_neurosynth_failure'] = False
        pytest.raises(RuntimeError, neurovault._download_image_terms,
                      image_info, collection, download_params)
        with open(
                os.path.join(collection['absolute_path'],
                             'neurosynth_words_for_image_a.json'), 'w'):
            pass
        neurovault._download_image_terms(image_info, collection,
                                         download_params)
Esempio n. 3
0
def test_download_image_terms():
    with _TestTemporaryDirectory() as temp_dir:
        image_info = {'id': 'a'}
        collection = {'relative_path': 'collection',
                      'absolute_path': os.path.join(temp_dir, 'collection')}
        os.makedirs(collection['absolute_path'])
        download_params = {'temp_dir': temp_dir, 'verbose': 3,
                           'fetch_neurosynth_words': True}
        with _FailingDownloads():
            neurovault._download_image_terms(
                image_info, collection, download_params)
            download_params['allow_neurosynth_failure'] = False
            assert_raises(RuntimeError,
                          neurovault._download_image_terms,
                          image_info, collection, download_params)
            with open(os.path.join(
                collection['absolute_path'],
                'neurosynth_words_for_image_a.json'), 'w'):
                pass
            neurovault._download_image_terms(
                image_info, collection, download_params)