MCPcopy Create free account
hub / github.com/huggingface/evaluate / ModuleFactoryTest

Class ModuleFactoryTest

tests/test_load.py:50–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48
49
50class ModuleFactoryTest(TestCase):
51 @pytest.fixture(autouse=True)
52 def inject_fixtures(self, metric_loading_script_dir):
53 self._metric_loading_script_dir = metric_loading_script_dir
54
55 def setUp(self):
56 self.hf_modules_cache = tempfile.mkdtemp()
57 self.cache_dir = tempfile.mkdtemp()
58 self.download_config = DownloadConfig(cache_dir=self.cache_dir)
59 self.dynamic_modules_path = evaluate.loading.init_dynamic_modules(
60 name="test_datasets_modules_" + os.path.basename(self.hf_modules_cache),
61 hf_modules_cache=self.hf_modules_cache,
62 )
63
64 def test_HubEvaluationModuleFactory_with_internal_import(self):
65 # "squad_v2" requires additional imports (internal)
66 factory = HubEvaluationModuleFactory(
67 "evaluate-metric/squad_v2",
68 module_type="metric",
69 download_config=self.download_config,
70 dynamic_modules_path=self.dynamic_modules_path,
71 )
72 module_factory_result = factory.get_module()
73 assert importlib.import_module(module_factory_result.module_path) is not None
74
75 def test_HubEvaluationModuleFactory_with_external_import(self):
76 # "bleu" requires additional imports (external from github)
77 factory = HubEvaluationModuleFactory(
78 "evaluate-metric/bleu",
79 module_type="metric",
80 download_config=self.download_config,
81 dynamic_modules_path=self.dynamic_modules_path,
82 )
83 module_factory_result = factory.get_module()
84 assert importlib.import_module(module_factory_result.module_path) is not None
85
86 def test_HubEvaluationModuleFactoryWithScript(self):
87 factory = HubEvaluationModuleFactory(
88 SAMPLE_METRIC_IDENTIFIER,
89 download_config=self.download_config,
90 dynamic_modules_path=self.dynamic_modules_path,
91 )
92 module_factory_result = factory.get_module()
93 assert importlib.import_module(module_factory_result.module_path) is not None
94
95 def test_LocalMetricModuleFactory(self):
96 path = os.path.join(self._metric_loading_script_dir, f"{METRIC_LOADING_SCRIPT_NAME}.py")
97 factory = LocalEvaluationModuleFactory(
98 path, download_config=self.download_config, dynamic_modules_path=self.dynamic_modules_path
99 )
100 module_factory_result = factory.get_module()
101 assert importlib.import_module(module_factory_result.module_path) is not None
102
103 def test_CachedMetricModuleFactory(self):
104 path = os.path.join(self._metric_loading_script_dir, f"{METRIC_LOADING_SCRIPT_NAME}.py")
105 factory = LocalEvaluationModuleFactory(
106 path, download_config=self.download_config, dynamic_modules_path=self.dynamic_modules_path
107 )

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…