1
0
Fork 0
mirror of synced 2024-12-04 13:25:34 -05:00
This commit is contained in:
Wanimatrix 2024-11-28 23:53:16 +00:00 committed by GitHub
commit 9dd6c0b5c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 43 additions and 1 deletions

View file

@ -18,7 +18,10 @@ class Dispatcher:
): ):
self._log = Messenger() self._log = Messenger()
self._setup_context(base_directory, options) self._setup_context(base_directory, options)
plugins = plugins or [] if plugins == None:
plugins = Plugin.__subclasses__()
else:
plugins = plugins or []
self._plugins = [plugin(self._context) for plugin in plugins] self._plugins = [plugin(self._context) for plugin in plugins]
self._only = only self._only = only
self._skip = skip self._skip = skip

View file

@ -0,0 +1,17 @@
"""Test that a plugin can call dispatcher for subtasks.
The plugin calls dispatch with his data.
"""
import os.path
import dotbot
class Dispatch(dotbot.Plugin):
def can_handle(self, directive):
return directive == "dispatch"
def handle(self, directive, data):
dispatcher = dotbot.dispatcher.Dispatcher(self._context.base_directory())
return dispatcher.dispatch(data)

22
tests/test_dispatcher.py Normal file
View file

@ -0,0 +1,22 @@
import os
import shutil
import pytest
def test_plugin_dispatcher(capfd, home, dotfiles, run_dotbot):
"""Verify that plugins can call dispatcher without explicitly specifying plugins."""
dotfiles.makedirs("plugins")
plugin_file = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "dotbot_plugin_dispatch.py"
)
shutil.copy(plugin_file, os.path.join(dotfiles.directory, "plugins", "dispatch.py"))
dotfiles.write_config(
[
{"dispatch": [{"create": ["~/a"]}]},
]
)
run_dotbot("--plugin-dir", os.path.join(dotfiles.directory, "plugins"))
assert os.path.exists(os.path.join(home, "a"))