mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 15:27:17 +00:00
drop ahriman.core.triggers.Trigger.run method
In order to force new triggers to use on_result method, the old method has been removed. However, default on_result method still checks if the old method exists and tries to run it
This commit is contained in:
parent
4bb598d2eb
commit
ad7cdb7d95
@ -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
|
||||
"""
|
||||
|
@ -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(), [])
|
||||
|
Loading…
Reference in New Issue
Block a user