Page MenuHomeSoftware Heritage

D4125.id14528.diff
No OneTemporary

D4125.id14528.diff

diff --git a/swh/loader/package/loader.py b/swh/loader/package/loader.py
--- a/swh/loader/package/loader.py
+++ b/swh/loader/package/loader.py
@@ -27,7 +27,7 @@
import attr
import sentry_sdk
-from swh.core.config import SWHConfig
+from swh.core.config import load_from_envvar
from swh.core.tarball import uncompress
from swh.loader.package.utils import download
from swh.model import from_disk
@@ -117,15 +117,17 @@
TPackageInfo = TypeVar("TPackageInfo", bound=BasePackageInfo)
+DEFAULT_CONFIG = {
+ "max_content_size": 100 * 1024 * 1024,
+ "create_authorities": True,
+ "create_fetchers": True,
+}
+
+
class PackageLoader(Generic[TPackageInfo]):
# Origin visit type (str) set by the loader
visit_type = ""
- DEFAULT_CONFIG = {
- "create_authorities": ("bool", True),
- "create_fetchers": ("bool", True),
- }
-
def __init__(self, url):
"""Loader's constructor. This raises exception if the minimal required
configuration is missing (cf. fn:`check` method).
@@ -135,7 +137,7 @@
"""
# This expects to use the environment variable SWH_CONFIG_FILENAME
- self.config = SWHConfig.parse_config_file()
+ self.config = load_from_envvar(DEFAULT_CONFIG)
self._check_configuration()
self.storage: StorageInterface = get_storage(**self.config["storage"])
self.url = url
diff --git a/swh/loader/package/pypi/tests/test_pypi.py b/swh/loader/package/pypi/tests/test_pypi.py
--- a/swh/loader/package/pypi/tests/test_pypi.py
+++ b/swh/loader/package/pypi/tests/test_pypi.py
@@ -3,11 +3,13 @@
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
+import copy
import os
from os import path
from unittest.mock import patch
import pytest
+import yaml
from swh.core.pytest_plugin import requests_mock_datadir_factory
from swh.core.tarball import uncompress
@@ -143,13 +145,25 @@
# configuration error #
-def test_badly_configured_loader_raise(monkeypatch):
- """Badly configured loader should raise"""
+def test_no_env_swh_config_filename_raise(monkeypatch):
+ """No SWH_CONFIG_FILENAME environment variable makes init raise"""
monkeypatch.delenv("SWH_CONFIG_FILENAME", raising=False)
- with pytest.raises(ValueError) as e:
+ with pytest.raises(AssertionError, match="environment variable is undefined"):
PyPILoader(url="some-url")
- assert "Misconfiguration" in e.value.args[0]
+
+def test_badly_configured_loader_raise(tmp_path, swh_loader_config, monkeypatch):
+ """Badly configured loader should raise"""
+ wrong_config = copy.deepcopy(swh_loader_config)
+ wrong_config.pop("storage")
+
+ conf_path = os.path.join(str(tmp_path), "loader.yml")
+ with open(conf_path, "w") as f:
+ f.write(yaml.dump(wrong_config))
+ monkeypatch.setenv("SWH_CONFIG_FILENAME", conf_path)
+
+ with pytest.raises(ValueError, match="Misconfiguration"):
+ PyPILoader(url="some-url")
def test_pypi_api_url():

File Metadata

Mime Type
text/plain
Expires
Thu, Jul 3, 1:06 PM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3232289

Event Timeline