diff --git a/src/ahriman/core/triggers/trigger.py b/src/ahriman/core/triggers/trigger.py index 783f66fc..86262d45 100644 --- a/src/ahriman/core/triggers/trigger.py +++ b/src/ahriman/core/triggers/trigger.py @@ -70,7 +70,8 @@ class Trigger(LazyLogging): result(Result): build result packages(Iterable[Package]): list of all available packages """ - self.run(result, packages) # compatibility with old triggers + if (run := getattr(self, "run", None)) is not None: + run(result, packages) # compatibility with old triggers def on_start(self) -> None: """ @@ -81,16 +82,3 @@ class Trigger(LazyLogging): """ trigger action which will be called before the stop of the application """ - - def run(self, result: Result, packages: Iterable[Package]) -> None: - """ - run trigger - - Note: - This method is deprecated and will be removed in the future versions. In order to run old-style trigger - action the ``on_result`` method must be used. - - Args: - result(Result): build result - packages(Iterable[Package]): list of all available packages - """ diff --git a/tests/ahriman/core/triggers/test_trigger.py b/tests/ahriman/core/triggers/test_trigger.py index a847d1d9..07581425 100644 --- a/tests/ahriman/core/triggers/test_trigger.py +++ b/tests/ahriman/core/triggers/test_trigger.py @@ -1,14 +1,23 @@ -from pytest_mock import MockerFixture +from unittest.mock import MagicMock from ahriman.core.triggers import Trigger from ahriman.models.result import Result -def test_on_result(trigger: Trigger, mocker: MockerFixture) -> None: +def test_on_result(trigger: Trigger) -> None: """ must pass execution nto run method """ - run_mock = mocker.patch("ahriman.core.triggers.Trigger.run") + trigger.on_result(Result(), []) + + +def test_on_result_run(trigger: Trigger) -> None: + """ + must fallback to run method if it exists + """ + run_mock = MagicMock() + setattr(trigger, "run", run_mock) + trigger.on_result(Result(), []) run_mock.assert_called_once_with(Result(), []) @@ -25,10 +34,3 @@ def test_on_stop(trigger: Trigger) -> None: must do nothing for not implemented method on_stop """ trigger.on_stop() - - -def test_run(trigger: Trigger) -> None: - """ - must do nothing for not implemented method run - """ - trigger.run(Result(), [])