Page MenuHomeSoftware Heritage

D4872.diff
No OneTemporary

D4872.diff

diff --git a/swh/lister/pattern.py b/swh/lister/pattern.py
--- a/swh/lister/pattern.py
+++ b/swh/lister/pattern.py
@@ -251,13 +251,15 @@
@classmethod
def from_configfile(cls, **kwargs: Any):
"""Instantiate a lister from the configuration loaded from the
- SWH_CONFIG_FILENAME envvar, with potential extra keyword arguments.
+ SWH_CONFIG_FILENAME envvar, with potential extra keyword arguments
+ if their value is not None.
Args:
kwargs: kwargs passed to the lister instantiation
"""
- config = load_from_envvar()
- return cls.from_config(**config, **kwargs)
+ config = dict(load_from_envvar())
+ config.update({k: v for k, v in kwargs.items() if v is not None})
+ return cls.from_config(**config)
class StatelessLister(Lister[None, PageType], Generic[PageType]):
diff --git a/swh/lister/tests/test_pattern.py b/swh/lister/tests/test_pattern.py
--- a/swh/lister/tests/test_pattern.py
+++ b/swh/lister/tests/test_pattern.py
@@ -39,6 +39,29 @@
lister.run()
+def test_instantiation_from_configfile(swh_scheduler, mocker):
+ mock_load_from_envvar = mocker.patch("swh.lister.pattern.load_from_envvar")
+ mock_get_scheduler = mocker.patch("swh.lister.pattern.get_scheduler")
+ mock_load_from_envvar.return_value = {
+ "scheduler": {},
+ "url": "foo",
+ "instance": "bar",
+ }
+ mock_get_scheduler.return_value = swh_scheduler
+
+ lister = InstantiableLister.from_configfile()
+ assert lister.url == "foo"
+ assert lister.instance == "bar"
+
+ lister = InstantiableLister.from_configfile(url="bar", instance="foo")
+ assert lister.url == "bar"
+ assert lister.instance == "foo"
+
+ lister = InstantiableLister.from_configfile(url=None, instance="foo")
+ assert lister.url == "foo"
+ assert lister.instance == "foo"
+
+
if TYPE_CHECKING:
_Base = pattern.Lister[Any, PageType]
else:

File Metadata

Mime Type
text/plain
Expires
Dec 20 2024, 7:46 AM (11 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3224007

Event Timeline