Adds missing module_specs for usages of _LazyModule (#15230)

* Add missing __spec__ for transformers.models.auto

* Moves the __spec__-test to the UnitTest class

* Adds module_spec to all instances of _LazyModule

* Refactors an old test from pytest to unittest
This commit is contained in:
Jonas Kuball
2022-01-21 13:30:12 +01:00
committed by GitHub
parent 6c7b68d414
commit c962c2adbf
101 changed files with 110 additions and 101 deletions

View File

@@ -13,10 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import importlib
import os
import tempfile
import unittest
import transformers.models.auto
from transformers.models.auto.configuration_auto import CONFIG_MAPPING, AutoConfig
from transformers.models.bert.configuration_bert import BertConfig
from transformers.models.roberta.configuration_roberta import RobertaConfig
@@ -31,6 +33,10 @@ class NewModelConfig(BertConfig):
class AutoConfigTest(unittest.TestCase):
def test_module_spec(self):
self.assertIsNotNone(transformers.models.auto.__spec__)
self.assertIsNotNone(importlib.util.find_spec("transformers.models.auto"))
def test_config_from_model_shortcut(self):
config = AutoConfig.from_pretrained("bert-base-uncased")
self.assertIsInstance(config, BertConfig)

View File

@@ -64,9 +64,11 @@ def context_fr():
print("Au revoir!")
def test_module_spec():
assert transformers.__spec__ is not None
assert importlib.util.find_spec("transformers") is not None
class TestImportMechanisms(unittest.TestCase):
def test_module_spec_available(self):
# If the spec is missing, importlib would not be able to import the module dynamically.
assert transformers.__spec__ is not None
assert importlib.util.find_spec("transformers") is not None
class GetFromCacheTests(unittest.TestCase):