def setUpModule(): destination = pathlib.Path("_test_cache/zipfiles/") for an in stdpopsim.all_annotations(): key = an.file_name local_file = destination / key if not local_file.exists(): cache_dir = local_file.parent cache_dir.mkdir(exist_ok=True, parents=True) print("Downloading", an.zarr_url) urllib.request.urlretrieve(an.zarr_url, local_file) saved_urls[key] = an.zarr_url an.zarr_url = local_file.resolve().as_uri()
def test_multiple_threads_downloading(self): gm = next(stdpopsim.all_annotations()) gm.download() saved = gm.is_cached try: # Trick the download code into thinking there's several happening # concurrently gm.is_cached = lambda: False with self.assertWarns(Warning): gm.download() finally: gm.is_cached = saved
def setUpModule(): destination = pathlib.Path("_test_cache/zipfiles/") for an in stdpopsim.all_annotations(): key = an._cache.cache_path local_file = destination / key if not local_file.exists(): cache_dir = local_file.parent cache_dir.mkdir(exist_ok=True, parents=True) print("Downloading", an.zarr_url) utils.download(an.zarr_url, local_file) # This assertion could fail if we update a file on AWS, # or a developer creates a new annotation with the wrong checksum # (in the latter case, this should at least be caught during CI tests). assert utils.sha256(local_file) == an.zarr_sha256, ( f"SHA256 for {local_file} doesn't match the SHA256 for " f"{an.id}. If you didn't add this SHA256 yourself, " f"try deleting {local_file} and restarting the tests.") saved_urls[key] = an.zarr_url an.zarr_url = local_file.resolve().as_uri() an._cache.url = an.zarr_url
def tearDownModule(): for an in stdpopsim.all_annotations(): an.zarr_url = saved_urls[an._cache.cache_path] an._cache.url = an.zarr_url
def teardown_module(): for an in stdpopsim.all_annotations(): an.intervals_url = saved_urls[an.id] an._cache.url = an.intervals_url
def tearDownModule(): for an in stdpopsim.all_annotations(): an.zarr_url = saved_urls[an.file_name]
def test_download_over_cache(self): for gm in stdpopsim.all_annotations(): gm.download() self.assertTrue(gm.is_cached()) gm.download() self.assertTrue(gm.is_cached())