parent
3e6e481a0f
commit
e464ff942b
@ -0,0 +1,94 @@
|
||||
# pylint: disable=redefined-outer-name
|
||||
from pathlib import Path
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
|
||||
from shepherd.agent import core
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def local_agent():
|
||||
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"
|
||||
Loading…
Reference in new issue