Skip to content

Commit 271ed7f

Browse files
authored
test: add FileNotFoundError test for get_file preset utility (#2768)
1 parent 601b176 commit 271ed7f

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

keras_hub/src/utils/preset_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ def find_subclass(preset, cls, backbone_cls):
124124

125125
def get_file(preset, path):
126126
"""Download a preset file in necessary and return the local path."""
127-
# TODO: Add tests for FileNotFound exceptions.
128127
if not isinstance(preset, str):
129128
raise ValueError(
130129
f"A preset identifier must be a string. Received: preset={preset}"

keras_hub/src/utils/preset_utils_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from keras_hub.src.tests.test_case import TestCase
1515
from keras_hub.src.utils.keras_utils import sharded_weights_available
1616
from keras_hub.src.utils.preset_utils import CONFIG_FILE
17+
from keras_hub.src.utils.preset_utils import get_file
1718
from keras_hub.src.utils.preset_utils import upload_preset
1819

1920

@@ -193,3 +194,10 @@ def test_upload_with_invalid_json(self):
193194
# Verify error handling.
194195
with self.assertRaisesRegex(ValueError, "is an invalid json"):
195196
upload_preset("kaggle://test/test/test", local_preset_dir)
197+
198+
def test_get_file_raises_file_not_found(self):
199+
local_dir = self.get_temp_dir()
200+
fake_path = "does_not_exist.json"
201+
202+
with self.assertRaises(FileNotFoundError):
203+
get_file(local_dir, fake_path)

0 commit comments

Comments
 (0)