Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ v6.1.9 (unreleased)
fixes:

- core: success handling for update_repos (#1520)
- core/plugins: cascade dependency plugins (#1519)

v6.1.8 (2021-06-21)
-------------------
Expand Down
3 changes: 2 additions & 1 deletion errbot/plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,8 @@ def _activate_plugin_dependencies(
dep_name,
dep_name,
)
self._activate_plugin_dependencies(dep_name, dep_track)
sub_depends_on = self._activate_plugin_dependencies(dep_name, dep_track)
dep_plugin.dependencies = sub_depends_on
self._activate_plugin(dep_plugin, dep_plugin_info)
return depends_on

Expand Down
35 changes: 35 additions & 0 deletions tests/cascade_dependencies_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
import pathlib

import mock
import pytest

extra_plugin_dir = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "cascade_dependent_plugins"
)

orig_path_glob = pathlib.Path.glob


def reordered_plugin_files(self, pattern):
if self.name == "cascade_dependent_plugins":
yield pathlib.Path(extra_plugin_dir + "/parent2.plug")
yield pathlib.Path(extra_plugin_dir + "/child1.plug")
yield pathlib.Path(extra_plugin_dir + "/child2.plug")
yield pathlib.Path(extra_plugin_dir + "/parent1.plug")
return
yield from orig_path_glob(self, pattern)


@pytest.fixture
def mock_before_bot_load():
patcher = mock.patch.object(pathlib.Path, "glob", reordered_plugin_files)
patcher.start()
yield
patcher.stop()


def test_dependency_commands(mock_before_bot_load, testbot):
assert "Hello from Child1" in testbot.exec_command("!parent1 to child1")
assert "Hello from Child2" in testbot.exec_command("!parent1 to child2")
assert "Hello from Parent1" in testbot.exec_command("!parent2 to parent1")
3 changes: 3 additions & 0 deletions tests/cascade_dependent_plugins/child1.plug
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Core]
Name = Child1
Module = child1
6 changes: 6 additions & 0 deletions tests/cascade_dependent_plugins/child1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from errbot import BotPlugin, botcmd


class Child1(BotPlugin):
def shared_function(self):
return "Hello from Child1"
3 changes: 3 additions & 0 deletions tests/cascade_dependent_plugins/child2.plug
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Core]
Name = Child2
Module = child2
6 changes: 6 additions & 0 deletions tests/cascade_dependent_plugins/child2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from errbot import BotPlugin, botcmd


class Child2(BotPlugin):
def shared_function(self):
return "Hello from Child2"
4 changes: 4 additions & 0 deletions tests/cascade_dependent_plugins/parent1.plug
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Core]
Name = Parent1
Module = parent1
DependsOn = Child1, Child2
14 changes: 14 additions & 0 deletions tests/cascade_dependent_plugins/parent1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from errbot import BotPlugin, botcmd


class Parent1(BotPlugin):
@botcmd
def parent1_to_child1(self, msg, args):
return self.get_plugin("Child1").shared_function()

@botcmd
def parent1_to_child2(self, msg, args):
return self.get_plugin("Child2").shared_function()

def shared_function(self):
return "Hello from Parent1"
4 changes: 4 additions & 0 deletions tests/cascade_dependent_plugins/parent2.plug
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Core]
Name = Parent2
Module = parent2
DependsOn = Parent1
7 changes: 7 additions & 0 deletions tests/cascade_dependent_plugins/parent2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from errbot import BotPlugin, botcmd


class Parent2(BotPlugin):
@botcmd
def parent2_to_parent1(self, msg, args):
return self.get_plugin("Parent1").shared_function()
14 changes: 14 additions & 0 deletions tests/circular_dependencies_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os

extra_plugin_dir = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "circular_dependent_plugins"
)
pytest_plugins = ["errbot.backends.test"]


def test_if_all_loaded_by_default(testbot):
"""https://github.com/errbotio/errbot/issues/1397"""
plug_names = testbot.bot.plugin_manager.get_all_active_plugin_names()
assert "PluginA" in plug_names
assert "PluginB" in plug_names
assert "PluginC" in plug_names
4 changes: 4 additions & 0 deletions tests/circular_dependent_plugins/pluginA.plug
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Core]
Name = PluginA
Module = pluginA
DependsOn = PluginB, PluginC
5 changes: 5 additions & 0 deletions tests/circular_dependent_plugins/pluginA.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from errbot import BotPlugin


class PluginA(BotPlugin):
pass
4 changes: 4 additions & 0 deletions tests/circular_dependent_plugins/pluginB.plug
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Core]
Name = PluginB
Module = pluginB
DependsOn = PluginC
5 changes: 5 additions & 0 deletions tests/circular_dependent_plugins/pluginB.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from errbot import BotPlugin


class PluginB(BotPlugin):
pass
3 changes: 3 additions & 0 deletions tests/circular_dependent_plugins/pluginC.plug
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Core]
Name = PluginC
Module = pluginC
5 changes: 5 additions & 0 deletions tests/circular_dependent_plugins/pluginC.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from errbot import BotPlugin


class PluginC(BotPlugin):
pass