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:
committed by
GitHub
parent
c69e23455d
commit
1cd110c6cb
@@ -189,3 +189,12 @@ class GetFromCacheTests(unittest.TestCase):
|
|||||||
with self.assertRaisesRegex(EnvironmentError, "is a gated repository"):
|
with self.assertRaisesRegex(EnvironmentError, "is a gated repository"):
|
||||||
# All files except README.md are protected on a gated repo.
|
# All files except README.md are protected on a gated repo.
|
||||||
has_file(GATED_REPO, "gated_file.txt", token=False)
|
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")
|
||||||
|
|||||||
Reference in New Issue
Block a user