Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/evaluate/loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,13 +617,19 @@ def evaluation_module_factory(
if path.endswith(filename):
if os.path.isfile(path):
return LocalEvaluationModuleFactory(
path, download_mode=download_mode, dynamic_modules_path=dynamic_modules_path
path,
download_config=download_config,
download_mode=download_mode,
dynamic_modules_path=dynamic_modules_path,
).get_module()
else:
raise FileNotFoundError(f"Couldn't find a metric script at {relative_to_absolute_path(path)}")
elif os.path.isfile(combined_path):
return LocalEvaluationModuleFactory(
combined_path, download_mode=download_mode, dynamic_modules_path=dynamic_modules_path
combined_path,
download_config=download_config,
download_mode=download_mode,
dynamic_modules_path=dynamic_modules_path,
).get_module()
elif is_relative_path(path) and path.count("/") <= 1 and not force_local_path:
try:
Expand Down
38 changes: 37 additions & 1 deletion tests/test_load.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import importlib
import os
import tempfile
from unittest import TestCase
from unittest import TestCase, mock

import pytest
from datasets import DownloadConfig
Expand Down Expand Up @@ -138,3 +138,39 @@ def test_cache_with_remote_community_module(self):
evaluation_module_factory(
metric, download_config=self.download_config, dynamic_modules_path=self.dynamic_modules_path
)

def test_evaluation_module_factory_passes_download_config_local_script(self):
"""Regression test for #709: download_config must be forwarded to LocalEvaluationModuleFactory
when loading a local .py file directly."""
path = os.path.join(self._metric_loading_script_dir, f"{METRIC_LOADING_SCRIPT_NAME}.py")
custom_config = DownloadConfig(cache_dir=self.cache_dir, local_files_only=True)
with mock.patch("evaluate.loading.LocalEvaluationModuleFactory") as mock_factory:
mock_factory.return_value.get_module.return_value = mock.MagicMock()
evaluation_module_factory(
path,
download_config=custom_config,
dynamic_modules_path=self.dynamic_modules_path,
)
mock_factory.assert_called_once()
_, call_kwargs = mock_factory.call_args
assert (
call_kwargs.get("download_config") is custom_config
), "download_config was not forwarded to LocalEvaluationModuleFactory for .py path"

def test_evaluation_module_factory_passes_download_config_local_dir(self):
"""Regression test for #709: download_config must be forwarded to LocalEvaluationModuleFactory
when loading a local directory (combined_path case)."""
path = self._metric_loading_script_dir
custom_config = DownloadConfig(cache_dir=self.cache_dir, local_files_only=True)
with mock.patch("evaluate.loading.LocalEvaluationModuleFactory") as mock_factory:
mock_factory.return_value.get_module.return_value = mock.MagicMock()
evaluation_module_factory(
path,
download_config=custom_config,
dynamic_modules_path=self.dynamic_modules_path,
)
mock_factory.assert_called_once()
_, call_kwargs = mock_factory.call_args
assert (
call_kwargs.get("download_config") is custom_config
), "download_config was not forwarded to LocalEvaluationModuleFactory for directory path"