You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.6 KiB
52 lines
1.6 KiB
# pylint: disable=redefined-outer-name
|
|
import pytest
|
|
from shepherd.agent import plugin
|
|
|
|
|
|
@pytest.fixture
|
|
def simple_plugin(request):
|
|
interface = plugin.load_plugin("simpletestplugin", request.fspath.dirname)
|
|
return interface
|
|
|
|
|
|
def test_simple_plugin_load(simple_plugin: plugin.PluginInterface):
|
|
# If successful, will load as if it's a custom plugin
|
|
assert simple_plugin._plugin_name == "simpletestplugin"
|
|
|
|
|
|
def test_simple_interface_function_load(simple_plugin: plugin.PluginInterface):
|
|
|
|
# Check register_function()
|
|
assert "my_interface_function" in simple_plugin._functions
|
|
|
|
|
|
@pytest.fixture
|
|
def simple_running_plugin(request):
|
|
interface = plugin.load_plugin("simpletestplugin", request.fspath.dirname)
|
|
template_config = interface.confspec.get_template()
|
|
plugin.init_plugins({"simpletestplugin": template_config}, {"core_conf": "core_conf_vals"})
|
|
return interface
|
|
|
|
|
|
def test_simple_plugin_init(simple_running_plugin):
|
|
assert "simpletestplugin" in plugin.plugin_interfaces
|
|
|
|
|
|
def test_simple_interface_functions(simple_running_plugin):
|
|
|
|
# Check module level function dict
|
|
assert plugin.plugin_functions["simpletestplugin"]["my_interface_function"]() == 42
|
|
|
|
# Check functions handed back to plugin
|
|
assert simple_running_plugin.plugins["simpletestplugin"].my_interface_function() == 42
|
|
|
|
|
|
def test_dirty_plugin_load(request):
|
|
"""
|
|
Corner cases in plugin load
|
|
"""
|
|
interface = plugin.load_plugin("dirtytestplugin", request.fspath.dirname)
|
|
|
|
# Should prefer the confspec actually registered, even if declared after
|
|
assert "spec2" in interface.confspec.spec_dict
|