Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/utils/test_hub_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,12 @@ def test_has_file_gated_repo(self):
with self.assertRaisesRegex(EnvironmentError, "is a gated repository"):
# All files except README.md are protected on a gated repo.
has_file(GATED_REPO, "gated_file.txt", token=False)

def test_cached_files_exception_raised(self):
"""Test that unhadled exceptions, e.g. ModuleNotFoundError, is properly re-raised by cached_files when hf_hub_download fails."""
with mock.patch(
"transformers.utils.hub.hf_hub_download", side_effect=ModuleNotFoundError("No module named 'MockModule'")
):
with self.assertRaises(ModuleNotFoundError):
# The error should be re-raised by cached_files, not caught in the exception handling block
cached_file(RANDOM_BERT, "nonexistent.json")