11import tempfile
22import unittest
33
4+ from bluemath_tk .downloaders ._download_result import DownloadResult
45from bluemath_tk .downloaders .copernicus .copernicus_downloader import (
56 CopernicusDownloader ,
67)
@@ -13,10 +14,10 @@ def setUp(self):
1314 product = "ERA5" ,
1415 base_path_to_download = self .temp_dir ,
1516 token = None ,
16- check = True , # Just check paths to download
1717 )
1818
1919 def test_download_data_era5 (self ):
20+ """Test downloading ERA5 data."""
2021 result = self .downloader .download_data_era5 (
2122 variables = ["spectra" ],
2223 years = [f"{ year :04d} " for year in range (2020 , 2025 )],
@@ -36,14 +37,108 @@ def test_download_data_era5(self):
3637 ],
3738 area = [43.4 , 350.4 , 43.6 , 350.6 ], # [lat_min, lon_min, lat_max, lon_max]
3839 )
40+ self .assertIsInstance (result , DownloadResult )
3941 print (result )
4042
43+ def test_download_data_era5_dry_run (self ):
44+ """Test dry_run functionality for ERA5."""
45+ result = self .downloader .download_data_era5 (
46+ variables = ["spectra" ],
47+ years = ["2020" ],
48+ months = ["01" ],
49+ area = [43.4 , 350.4 , 43.6 , 350.6 ],
50+ dry_run = True ,
51+ )
52+ self .assertIsInstance (result , DownloadResult )
53+ self .assertTrue (
54+ len (result .skipped_files ) > 0 or len (result .downloaded_files ) > 0
55+ )
56+ print (f"\n Dry run result: { result } " )
4157
42- if __name__ == "__main__" :
43- unittest .main ()
58+ def test_download_data_routing (self ):
59+ """Test that download_data routes to product-specific methods."""
60+ result = self .downloader .download_data (
61+ variables = ["spectra" ],
62+ years = ["2020" ],
63+ months = ["01" ],
64+ dry_run = True ,
65+ )
66+ self .assertIsInstance (result , DownloadResult )
67+
68+ def test_product_parameter (self ):
69+ """Test that product parameter is required and validated."""
70+ # Test with valid product ERA5
71+ downloader = CopernicusDownloader (
72+ product = "ERA5" ,
73+ base_path_to_download = self .temp_dir ,
74+ )
75+ self .assertEqual (downloader .product , "ERA5" )
76+
77+ # Test with valid product CERRA
78+ downloader = CopernicusDownloader (
79+ product = "CERRA" ,
80+ base_path_to_download = self .temp_dir ,
81+ )
82+ self .assertEqual (downloader .product , "CERRA" )
83+
84+ # Test with invalid product
85+ with self .assertRaises (ValueError ):
86+ CopernicusDownloader (
87+ product = "INVALID" ,
88+ base_path_to_download = self .temp_dir ,
89+ )
4490
91+ def test_list_variables (self ):
92+ """Test listing available variables."""
93+ variables = self .downloader .list_variables ()
94+ self .assertIsInstance (variables , list )
95+ self .assertTrue (len (variables ) > 0 )
96+ print (f"\n Available variables: { variables } " )
4597
46- # mean_wave_period_based_on_first_moment/
47- # wave_spectral_directional_width/
48- # wave_spectral_directional_width_for_swell/
49- # wave_spectral_directional_width_for_wind_waves/
98+ def test_list_datasets (self ):
99+ """Test listing available datasets."""
100+ datasets = self .downloader .list_datasets ()
101+ self .assertIsInstance (datasets , list )
102+ self .assertTrue (len (datasets ) > 0 )
103+ print (f"\n Available datasets: { datasets } " )
104+
105+ def test_download_data_cerra (self ):
106+ """Test downloading CERRA data."""
107+ cerra_downloader = CopernicusDownloader (
108+ product = "CERRA" ,
109+ base_path_to_download = self .temp_dir ,
110+ token = None ,
111+ )
112+ result = cerra_downloader .download_data_cerra (
113+ variables = ["10m_wind_speed" ],
114+ years = ["2020" ],
115+ months = ["01" ],
116+ days = ["01" ],
117+ dry_run = True ,
118+ )
119+ self .assertIsInstance (result , DownloadResult )
120+ print (f"\n CERRA download result: { result } " )
121+
122+ def test_download_data_cerra_dry_run (self ):
123+ """Test dry_run functionality for CERRA."""
124+ cerra_downloader = CopernicusDownloader (
125+ product = "CERRA" ,
126+ base_path_to_download = self .temp_dir ,
127+ token = None ,
128+ )
129+ result = cerra_downloader .download_data_cerra (
130+ variables = ["10m_wind_direction" ],
131+ years = ["2020" ],
132+ months = ["01" ],
133+ days = ["01" ],
134+ dry_run = True ,
135+ )
136+ self .assertIsInstance (result , DownloadResult )
137+ self .assertTrue (
138+ len (result .skipped_files ) > 0 or len (result .downloaded_files ) > 0
139+ )
140+ print (f"\n CERRA dry run result: { result } " )
141+
142+
143+ if __name__ == "__main__" :
144+ unittest .main ()
0 commit comments