|
| 1 | +import os |
| 2 | +import shutil |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +import pooch |
| 6 | +import pytest |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture(scope="session") |
| 10 | +def testdata_path() -> Path: |
| 11 | + TEST_DIR = Path(__file__).parent |
| 12 | + return TEST_DIR / "data/" |
| 13 | + |
| 14 | + |
| 15 | +@pytest.fixture(scope="session") |
| 16 | +def zenodo_zarr(testdata_path: Path) -> list[str]: |
| 17 | + """ |
| 18 | + This takes care of multiple steps: |
| 19 | +
|
| 20 | + 1. Download/unzip two Zarr containers (3D and MIP) from Zenodo, via pooch |
| 21 | + 2. Copy the two Zarr containers into tests/data |
| 22 | + 3. Modify the Zarrs in tests/data, to add whatever is not in Zenodo |
| 23 | + """ |
| 24 | + |
| 25 | + # 1 Download Zarrs from Zenodo |
| 26 | + DOI = "10.5281/zenodo.10257149" |
| 27 | + DOI_slug = DOI.replace("/", "_").replace(".", "_") |
| 28 | + platenames = ["plate.zarr", "plate_mip.zarr"] |
| 29 | + rootfolder = testdata_path / DOI_slug |
| 30 | + folders = [rootfolder / plate for plate in platenames] |
| 31 | + |
| 32 | + registry = { |
| 33 | + "20200812-CardiomyocyteDifferentiation14-Cycle1.zarr.zip": None, |
| 34 | + "20200812-CardiomyocyteDifferentiation14-Cycle1_mip.zarr.zip": None, |
| 35 | + } |
| 36 | + base_url = f"doi:{DOI}" |
| 37 | + POOCH = pooch.create( |
| 38 | + pooch.os_cache("pooch") / DOI_slug, |
| 39 | + base_url, |
| 40 | + registry=registry, |
| 41 | + retry_if_failed=10, |
| 42 | + allow_updates=False, |
| 43 | + ) |
| 44 | + |
| 45 | + for ind, file_name in enumerate( |
| 46 | + [ |
| 47 | + "20200812-CardiomyocyteDifferentiation14-Cycle1.zarr", |
| 48 | + "20200812-CardiomyocyteDifferentiation14-Cycle1_mip.zarr", |
| 49 | + ] |
| 50 | + ): |
| 51 | + # 1) Download/unzip a single Zarr from Zenodo |
| 52 | + file_paths = POOCH.fetch( |
| 53 | + f"{file_name}.zip", processor=pooch.Unzip(extract_dir=file_name) |
| 54 | + ) |
| 55 | + zarr_full_path = file_paths[0].split(file_name)[0] + file_name |
| 56 | + print(zarr_full_path) |
| 57 | + folder = folders[ind] |
| 58 | + |
| 59 | + # 2) Copy the downloaded Zarr into tests/data |
| 60 | + if os.path.isdir(str(folder)): |
| 61 | + shutil.rmtree(str(folder)) |
| 62 | + shutil.copytree(Path(zarr_full_path) / file_name, folder) |
| 63 | + return [str(f) for f in folders] |
| 64 | + |
| 65 | + |
| 66 | +@pytest.fixture(scope="function") |
| 67 | +def tmp_zenodo_zarr(zenodo_zarr: list[str], tmpdir: Path) -> list[str]: |
| 68 | + """Generates a copy of the zenodo zarrs in a tmpdir""" |
| 69 | + zenodo_mip_path = str(tmpdir / Path(zenodo_zarr[1]).name) |
| 70 | + zenodo_path = str(tmpdir / Path(zenodo_zarr[0]).name) |
| 71 | + shutil.copytree(zenodo_zarr[0], zenodo_path) |
| 72 | + shutil.copytree(zenodo_zarr[1], zenodo_mip_path) |
| 73 | + return [zenodo_path, zenodo_mip_path] |
0 commit comments