File tree Expand file tree Collapse file tree 2 files changed +15
-6
lines changed
src/power_grid_model_io/utils Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -214,12 +214,8 @@ def get_download_path(
214
214
unique_key: A unique string that can be used to generate a filename (e.g. a url).
215
215
"""
216
216
217
- # If no dir_path is given, use the system's designated folder for temporary files.
218
- if dir_path is None :
219
- dir_path = Path (tempfile .gettempdir ())
220
-
221
217
# If no specific download path was given, we need to generate a unique key (based on the given unique key)
222
- if file_name is None or unique_key is not None :
218
+ if dir_path is None or file_name is None :
223
219
if unique_key is None :
224
220
raise ValueError ("Supply a unique key in order to auto generate a download path." )
225
221
@@ -233,7 +229,12 @@ def get_download_path(
233
229
file_name = Path (f"{ unique_key } .download" )
234
230
# Otherwise, use the unique key as a sub directory
235
231
else :
236
- dir_path /= unique_key
232
+ assert dir_path is None # sanity check
233
+ dir_path = Path (tempfile .gettempdir ()) / unique_key
234
+
235
+ # If no dir_path is given, use the system's designated folder for temporary files.
236
+ if dir_path is None :
237
+ dir_path = Path (tempfile .gettempdir ())
237
238
238
239
# Combine the two paths
239
240
assert file_name is not None
Original file line number Diff line number Diff line change @@ -366,6 +366,14 @@ def test_get_download_path(temp_dir: Path):
366
366
assert path == temp_dir / "file_name.zip"
367
367
368
368
369
+ def test_get_download_path__ignore_unique_key (temp_dir : Path ):
370
+ # Act
371
+ path = get_download_path (dir_path = temp_dir , file_name = "file_name.zip" , unique_key = "foo" )
372
+
373
+ # Assert
374
+ assert path == temp_dir / "file_name.zip"
375
+
376
+
369
377
def test_get_download_path__auto_dir ():
370
378
# Act
371
379
path = get_download_path (file_name = "file_name.zip" , unique_key = "foo" )
You can’t perform that action at this time.
0 commit comments