-
Notifications
You must be signed in to change notification settings - Fork 7
/
conftest.py
51 lines (40 loc) · 1.6 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import shutil
from pathlib import Path
from typing import Generator
import pytest
import requests
from readimc import MCDFile, TXTFile
_imc_test_data_asset_url = (
"https://github.com/BodenmillerGroup/TestData"
"/releases/download/v1.0.7/210308_ImcTestData_raw.tar.gz"
)
_imc_test_data_raw_dir = "datasets/210308_ImcTestData/raw"
_imc_test_data_mcd_file = "20210305_NE_mockData1/20210305_NE_mockData1.mcd"
_imc_test_data_txt_file = "20210305_NE_mockData1/20210305_NE_mockData1_ROI_001_1.txt"
def _download_and_extract_asset(tmp_dir_path: Path, asset_url: str):
asset_file_path = tmp_dir_path / "asset.tar.gz"
response = requests.get(asset_url, stream=True)
if response.status_code == 200:
with asset_file_path.open(mode="wb") as f:
f.write(response.raw.read())
shutil.unpack_archive(asset_file_path, tmp_dir_path)
@pytest.fixture(scope="session")
def imc_test_data_raw_path(tmp_path_factory) -> Generator[Path, None, None]:
tmp_dir_path = tmp_path_factory.mktemp("raw")
_download_and_extract_asset(tmp_dir_path, _imc_test_data_asset_url)
yield tmp_dir_path / Path(_imc_test_data_raw_dir)
shutil.rmtree(tmp_dir_path)
@pytest.fixture
def imc_test_data_mcd_file(
imc_test_data_raw_path: Path,
) -> Generator[MCDFile, None, None]:
path = imc_test_data_raw_path / Path(_imc_test_data_mcd_file)
with MCDFile(path) as f:
yield f
@pytest.fixture
def imc_test_data_txt_file(
imc_test_data_raw_path: Path,
) -> Generator[TXTFile, None, None]:
path = imc_test_data_raw_path / Path(_imc_test_data_txt_file)
with TXTFile(path) as f:
yield f