def test_file_url_not_found(): data_filename = "data/cmu_small_region_broken.svs" with pytest.raises(HTTPError) as err: _fetch(data_filename) assert ( str(err.value) == f"404 Client Error: Not Found for url: " f"https://github.com/histolab/histolab/raw/{v}/histolab/{data_filename}" )
def it_raises_error_on_fetch_if_image_fetcher_is_None(): with pytest.raises(ModuleNotFoundError) as err: _fetch("data/cmu_small_region.svs") assert ( str(err.value) == "The requested file is part of the histolab distribution, but requires the " "installation of an optional dependency, pooch. To install pooch, use your " "preferred python package manager. Follow installation instruction found at " "https://www.fatiando.org/pooch/latest/install.html")
def test_download_file_from_internet(): # NOTE: This test will be skipped when internet connection is not available fetch("histolab/kidney.png") kidney_path = _fetch("histolab/kidney.png") kidney_image = np.array(PIL.Image.open(kidney_path)) assert kidney_image.shape == (537, 809, 4)
def fetch(data_filename): """Attempt to fetch data, but if unavailable, skip the tests.""" try: return data._fetch(data_filename) except (ConnectionError, ModuleNotFoundError): pytest.skip(f"Unable to download {data_filename}")