From dd7c661db40da3e5c89da80800c543535273bcd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=A9=E7=80=9A=E7=8C=AB?= Date: Tue, 20 Aug 2024 12:58:13 +0900 Subject: [PATCH] update data.tests for pytest parallel --- .github/workflows/pytest.yml | 3 +++ easyidp/data.py | 9 ++++----- tests/test_data.py | 38 +++++++++++++++++++++++++++--------- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index ba7aa60..81be948 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -32,6 +32,9 @@ jobs: python -m pip install --upgrade pip pip install -r requirements/default.txt pip install -r requirements/test.txt + - name: Download TestData + run: | + python ./tests/__init__.py - name: Run pytest run: | pytest -n auto diff --git a/easyidp/data.py b/easyidp/data.py index 4818129..004b181 100644 --- a/easyidp/data.py +++ b/easyidp/data.py @@ -4,7 +4,6 @@ import zipfile import requests import subprocess -import webbrowser import tqdm from pathlib import Path @@ -256,13 +255,13 @@ class EasyidpDataSet(): """The base class for Dataset """ - def __init__(self, name="", gdrive_url="", size="",): + def __init__(self, name="", gdrive_url="", size=""): """The dataset has the following properties (almost in string type) name The dataset name - url_list - The possible download urls + gdrive_url + The google drive download urls size Ths size of zipped file data_dir @@ -529,7 +528,7 @@ def __init__(self): self.metashape.dsm = self.data_dir / "Hidden_Little_03_24_2022_DEM.tif" class GDownTest(EasyidpDataSet): - """The data for Google Drive and Aliyun OSS download testing + """The data for Google Drive download testing """ def __init__(self): diff --git a/tests/test_data.py b/tests/test_data.py index b95f25f..8d5942b 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -131,7 +131,7 @@ def mock_requests_get(): def test_download_success(): dataset_name = "gdown_test" - output = "./tests/out/data_test/gdown_test.zip" + output = "./tests/out/data_test/gdown_download_test.zip" if os.path.exists(output): os.remove(output) @@ -153,15 +153,31 @@ def test_download_auth_failure(mock_requests_get): #-------------------- def test_gdown_ali_oss(): - gd_dir = idp.data.user_data_dir("gdown_test") + # the default EasyIDPDataset using system cache folder + # it conflits when pytest parallel + # -> previous `gdown_test` function may delete the same folder + # thus made an unique test, which can specify unzip folder + from easyidp.data import EasyidpDataSet, GDOWN_TEST_URL + class ADownTest(EasyidpDataSet): + def __init__(self, dataset_folder:Path): + + super().__init__("gdown_test", GDOWN_TEST_URL, "0.2KB") + self.data_dir = dataset_folder / self.name + self.zip_file = dataset_folder / (self.name + ".zip") + + super().load_data() + + self.pix4d.proj = self.data_dir / "file1.txt" + self.metashape.param = self.data_dir / "folder1" + # end of unique testing class + + dataset_folder = Path('./tests/out/data_test/') + data_dir = dataset_folder / "gdown_test" # clear already existed folder for `gdown_test` - if gd_dir.exists(): - shutil.rmtree(gd_dir) + if data_dir.exists(): + shutil.rmtree(data_dir) - # force to use AliYUN OSS - idp.GOOGLE_AVAILABLE = False - # ask if China mainland, answer: no # google drive not available, and not in china mainland # => not provide aliyun oss service for overseas, @@ -174,12 +190,16 @@ def test_gdown_ali_oss(): "Could not find proper downloadable link for dataset gdown_test." ) ): - gd = idp.data.GDownTest() + # force to use AliYUN OSS + idp.GOOGLE_AVAILABLE = False + gd = ADownTest(dataset_folder=dataset_folder) # ask if China mainland, answer: yes inputs = ["y", "我已知悉此次下载会消耗0.0元的下行流量费用"] with patch('builtins.input', side_effect=inputs): - gd = idp.data.GDownTest() + # force to use AliYUN OSS + idp.GOOGLE_AVAILABLE = False + gd = ADownTest(dataset_folder=dataset_folder) assert gd.data_dir.exists() assert (gd.data_dir / "file1.txt").exists() \ No newline at end of file