Skip to content

Commit c9a25c8

Browse files
committed
Fix auto_dir bug
Signed-off-by: Bram Stoeller <[email protected]>
1 parent 44c764a commit c9a25c8

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/power_grid_model_io/utils/download.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def get_download_path(
215215
"""
216216

217217
# If no specific download path was given, we need to generate a unique key (based on the given unique key)
218-
if dir_path is None or file_name is None:
218+
if file_name is None or unique_key is not None:
219219
if unique_key is None:
220220
raise ValueError("Supply a unique key in order to auto generate a download path.")
221221

@@ -228,8 +228,7 @@ def get_download_path(
228228
if file_name is None:
229229
file_name = Path(f"{unique_key}.download")
230230
# Otherwise, use the unique key as a sub directory
231-
else:
232-
assert dir_path is None # sanity check
231+
elif dir_path is None:
233232
dir_path = Path(tempfile.gettempdir()) / unique_key
234233

235234
# If no dir_path is given, use the system's designated folder for temporary files.

tests/unit/utils/test_download.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
# The / and + will be replaced with a _ and - character and the trailing = character(s) will be removed.
2727
FOO_KEY = "LCa0a2j_xo_5m0U8HTBBNBNCLXBkg7-g-YpeiGJm564"
2828

29+
TEMP_DIR = Path(tempfile.gettempdir()).resolve()
30+
2931

3032
@pytest.fixture()
3133
def temp_dir():
@@ -374,12 +376,20 @@ def test_get_download_path__ignore_unique_key(temp_dir: Path):
374376
assert path == temp_dir / "file_name.zip"
375377

376378

379+
def test_get_download_path__temp_dir():
380+
# Act
381+
path = get_download_path(file_name="file_name.zip")
382+
383+
# Assert
384+
assert path == TEMP_DIR / "file_name.zip"
385+
386+
377387
def test_get_download_path__auto_dir():
378388
# Act
379389
path = get_download_path(file_name="file_name.zip", unique_key="foo")
380390

381391
# Assert
382-
assert path == Path(tempfile.gettempdir()).resolve() / FOO_KEY / "file_name.zip"
392+
assert path == TEMP_DIR / FOO_KEY / "file_name.zip"
383393

384394

385395
def test_get_download_path__auto_file_name(temp_dir: Path):

0 commit comments

Comments
 (0)