Skip to content

Commit 44c764a

Browse files
committed
Only use unique key for dirs if no dir_path was given
Signed-off-by: Bram Stoeller <bram.stoeller@alliander.com>
1 parent 216f1ed commit 44c764a

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/power_grid_model_io/utils/download.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,8 @@ def get_download_path(
214214
unique_key: A unique string that can be used to generate a filename (e.g. a url).
215215
"""
216216

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-
221217
# 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:
223219
if unique_key is None:
224220
raise ValueError("Supply a unique key in order to auto generate a download path.")
225221

@@ -233,7 +229,12 @@ def get_download_path(
233229
file_name = Path(f"{unique_key}.download")
234230
# Otherwise, use the unique key as a sub directory
235231
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())
237238

238239
# Combine the two paths
239240
assert file_name is not None

tests/unit/utils/test_download.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,14 @@ def test_get_download_path(temp_dir: Path):
366366
assert path == temp_dir / "file_name.zip"
367367

368368

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+
369377
def test_get_download_path__auto_dir():
370378
# Act
371379
path = get_download_path(file_name="file_name.zip", unique_key="foo")

0 commit comments

Comments
 (0)