1515from pathlib import Path
1616from urllib .error import ContentTooShortError , HTTPError
1717
18+ from parameterized import parameterized
19+
1820from monai .apps import download_and_extract , download_url , extractall
19- from tests .utils import skip_if_downloading_fails , skip_if_quick
21+ from tests .utils import skip_if_downloading_fails , skip_if_quick , testing_data_config
2022
2123
2224class TestDownloadAndExtract (unittest .TestCase ):
2325 @skip_if_quick
2426 def test_actions (self ):
2527 testing_dir = os .path .join (os .path .dirname (os .path .realpath (__file__ )), "testing_data" )
26- url = "https://drive.google.com/uc?id=1QsnnkvZyJPcbRoV_ArW8SnE1OTuoVbKE"
28+ config_dict = testing_data_config ("images" , "mednist" )
29+ url = config_dict ["url" ]
2730 filepath = Path (testing_dir ) / "MedNIST.tar.gz"
2831 output_dir = Path (testing_dir )
29- md5_value = "0bc7306e7427e00ad1c5526a6677552d"
32+ hash_val , hash_type = config_dict [ "hash_val" ], config_dict [ "hash_type" ]
3033 with skip_if_downloading_fails ():
31- download_and_extract (url , filepath , output_dir , md5_value )
32- download_and_extract (url , filepath , output_dir , md5_value )
34+ download_and_extract (url , filepath , output_dir , hash_val = hash_val , hash_type = hash_type )
35+ download_and_extract (url , filepath , output_dir , hash_val = hash_val , hash_type = hash_type )
3336
3437 wrong_md5 = "0"
3538 with self .assertLogs (logger = "monai.apps" , level = "ERROR" ):
@@ -47,22 +50,17 @@ def test_actions(self):
4750 self .assertTrue (str (e ).startswith ("md5 check" ))
4851
4952 @skip_if_quick
50- def test_default (self ):
53+ @parameterized .expand ((("icon" , "tar" ), ("favicon" , "zip" )))
54+ def test_default (self , key , file_type ):
5155 with tempfile .TemporaryDirectory () as tmp_dir :
5256 with skip_if_downloading_fails ():
53- # icon.tar.gz https://drive.google.com/file/d/1HrQd-AKPbts9jkTNN4pT8vLZyhM5irVn/view?usp=sharing
54- download_and_extract (
55- "https://drive.google.com/uc?id=1HrQd-AKPbts9jkTNN4pT8vLZyhM5irVn" ,
56- output_dir = tmp_dir ,
57- hash_val = "a55d11ad26ed9eb7277905d796205531" ,
58- file_type = "tar" ,
59- )
60- # favicon.ico.zip https://drive.google.com/file/d/1TqBTJap621NO9arzXRrYi04lr9NTVF8H/view?usp=sharing
57+ img_spec = testing_data_config ("images" , key )
6158 download_and_extract (
62- "https://drive.google.com/uc?id=1TqBTJap621NO9arzXRrYi04lr9NTVF8H" ,
59+ img_spec [ "url" ] ,
6360 output_dir = tmp_dir ,
64- hash_val = "ac6e167ee40803577d98237f2b0241e5" ,
65- file_type = "zip" ,
61+ hash_val = img_spec ["hash_val" ],
62+ hash_type = img_spec ["hash_type" ],
63+ file_type = file_type ,
6664 )
6765
6866
0 commit comments