Add plugin dispatch test
Add test to verify that a plugin can run dispatch to handle subtasks of external plugins.
This commit is contained in:
parent
8bd46a6549
commit
e2c455213c
2 changed files with 39 additions and 0 deletions
17
tests/dotbot_plugin_dispatch.py
Normal file
17
tests/dotbot_plugin_dispatch.py
Normal 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
22
tests/test_dispatcher.py
Normal 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"))
|
Loading…
Reference in a new issue