mirror of
https://github.com/huggingface/transformers.git
synced 2025-07-31 02:02:21 +06:00
Add test to ensure unknown exceptions reraising in utils/hub.py::cached_files() (#37651)
* add test to ensure unknown exceptions are reraised in utils/hub.py::cached_files()
This commit is contained in:
parent
c69e23455d
commit
1cd110c6cb
@ -189,3 +189,12 @@ class GetFromCacheTests(unittest.TestCase):
|
||||
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")
|
||||
|
Loading…
Reference in New Issue
Block a user