Skip to content

Commit

Permalink
update data.tests for pytest parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
HowcanoeWang committed Aug 20, 2024
1 parent 9a5e8d4 commit dd7c661
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 4 additions & 5 deletions easyidp/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import zipfile
import requests
import subprocess
import webbrowser
import tqdm
from pathlib import Path

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
38 changes: 29 additions & 9 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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()

0 comments on commit dd7c661

Please sign in to comment.