forked from huggingface/transformers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test fn for clearing import cache
- Loading branch information
1 parent
0fd0cf4
commit 05ca48f
Showing
1 changed file
with
28 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,30 @@ | ||
import sys | ||
import pytest | ||
from transformers.utils.import_utils import clear_import_cache, _LazyModule | ||
from transformers.utils.import_utils import clear_import_cache, _LazyModule | ||
|
||
def test_clear_import_cache(): | ||
# Import some transformers modules | ||
from transformers import AutoModel, AutoTokenizer | ||
|
||
# Get initial module count | ||
initial_modules = { | ||
name: mod for name, mod in sys.modules.items() | ||
if name.startswith('transformers.') | ||
} | ||
|
||
# Verify we have some modules loaded | ||
assert len(initial_modules) > 0 | ||
|
||
# Clear cache | ||
clear_import_cache() | ||
|
||
# Check modules were removed | ||
remaining_modules = { | ||
name: mod for name, mod in sys.modules.items() | ||
if name.startswith('transformers.') | ||
} | ||
assert len(remaining_modules) < len(initial_modules) | ||
|
||
# Verify we can reimport | ||
from transformers import AutoModel, AutoTokenizer | ||
assert 'transformers.models.auto.modeling_auto' in sys.modules |