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.
105 lines
2.8 KiB
105 lines
2.8 KiB
# pylint: disable=redefined-outer-name
|
|
from pathlib import Path
|
|
import logging
|
|
|
|
import pytest
|
|
|
|
from shepherd.agent import core
|
|
from shepherd.agent import plugin
|
|
|
|
|
|
@pytest.fixture
|
|
def local_agent():
|
|
plugin.unload_plugins()
|
|
return core.Agent(control_enabled=False)
|
|
|
|
|
|
@pytest.fixture
|
|
def basic_config(tmp_path):
|
|
def_conf_file = tmp_path / "shepherd_default.toml"
|
|
def_conf_file.write_text("""
|
|
[shepherd]
|
|
name = "shepherd-test"
|
|
""")
|
|
return def_conf_file
|
|
|
|
|
|
@pytest.fixture
|
|
def custom_config(tmp_path):
|
|
def_conf_file = tmp_path / "shepherd_default.toml"
|
|
def_conf_file.write_text("""
|
|
[shepherd]
|
|
name = "shepherd-test"
|
|
custom_config_path = "shepherd_custom.toml"
|
|
""")
|
|
custom_conf_file = tmp_path / "shepherd_custom.toml"
|
|
custom_conf_file.write_text("""
|
|
[shepherd]
|
|
name = "shepherd-custom"
|
|
""")
|
|
return def_conf_file
|
|
|
|
|
|
@pytest.fixture
|
|
def plugin_config(tmp_path, request):
|
|
plugin_dir = Path(request.fspath.dirname)/'assets'
|
|
def_conf_file = tmp_path / "shepherd_default.toml"
|
|
def_conf_file.write_text(F"""
|
|
[shepherd]
|
|
name = "shepherd-test"
|
|
plugin_dir = "{plugin_dir}"
|
|
[classtestplugin]
|
|
spec1 = "asdf"
|
|
""")
|
|
return def_conf_file
|
|
|
|
|
|
def test_local_agent(local_agent):
|
|
pass
|
|
|
|
|
|
def test_local_agent_load(local_agent, basic_config):
|
|
local_agent.load(basic_config)
|
|
|
|
|
|
def test_local_compiled_conf(local_agent, basic_config):
|
|
local_agent.load(basic_config)
|
|
compiled_conf = (basic_config.parent / "compiled-config.toml").read_text()
|
|
assert 'name = "shepherd-test"' in compiled_conf
|
|
# Paths should be resolved to absolute
|
|
assert 'plugin_dir = "/' in compiled_conf
|
|
assert 'Compiled Shepherd config' in compiled_conf
|
|
|
|
|
|
def test_custom_conf_load(local_agent, custom_config):
|
|
local_agent.load(custom_config)
|
|
assert local_agent.core_config["name"] == "shepherd-custom"
|
|
|
|
|
|
def test_new_device_trigger(local_agent, custom_config, caplog):
|
|
caplog.set_level(logging.INFO)
|
|
(custom_config.parent / "shepherd.new").touch()
|
|
local_agent.load(custom_config)
|
|
assert "'new device' mode enabled" in caplog.text
|
|
assert (custom_config.parent / "shepherd.identity").exists()
|
|
|
|
|
|
def test_local_agent_start(local_agent, basic_config):
|
|
local_agent.load(basic_config)
|
|
local_agent.start()
|
|
|
|
|
|
def test_local_agent_plugin_start(local_agent, plugin_config):
|
|
local_agent.load(plugin_config)
|
|
local_agent.start()
|
|
assert local_agent.interface_functions["classtestplugin"].instance_method(
|
|
3) == "instance method 3"
|
|
|
|
|
|
def test_core_interface(local_agent, plugin_config):
|
|
local_agent.load(plugin_config)
|
|
local_agent.start()
|
|
plugin_interface = local_agent.plugin_interfaces["classtestplugin"]
|
|
assert plugin_interface.plugins["shepherd"].device_name() == "shepherd-test"
|
|
assert plugin_interface.plugins["shepherd"].root_dir() == str(plugin_config.parent)
|