41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
"""Plugin system enhancement tests"""
|
|
import pytest, asyncio, os, sys
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
|
|
|
from sdk.plugin_status import PluginStatus
|
|
from sdk.plugin_error import (
|
|
PluginError, PluginLoadError, PluginConfigError,
|
|
PluginPermissionError, PluginCommandError
|
|
)
|
|
|
|
class TestPluginStatus:
|
|
def test_all_statuses(self):
|
|
assert PluginStatus.UNLOADED == "unloaded"
|
|
assert PluginStatus.RUNNING == "running"
|
|
assert PluginStatus.ERROR == "error"
|
|
assert len(list(PluginStatus)) >= 8
|
|
|
|
class TestPluginError:
|
|
def test_base_error(self):
|
|
e = PluginError("test message", "test_plugin")
|
|
assert "test_plugin" in str(e)
|
|
assert "test message" in str(e)
|
|
|
|
def test_error_without_plugin_name(self):
|
|
e = PluginError("generic error")
|
|
assert "unknown" in str(e)
|
|
|
|
def test_subclass_errors(self):
|
|
for cls in [PluginLoadError, PluginConfigError, PluginPermissionError, PluginCommandError]:
|
|
e = cls("msg", "p")
|
|
assert isinstance(e, PluginError)
|
|
|
|
class TestPluginBridgeEnhancements:
|
|
def test_subscribe_plugin_registers_handler(self):
|
|
from bridges.plugin_bridge import PluginBridge
|
|
from bridges.core_bridge import CoreBridge
|
|
cb = CoreBridge()
|
|
pb = PluginBridge(cb)
|
|
pb.subscribe_plugin("test.topic", lambda msg: None, "test_plugin")
|
|
assert "test.topic" in pb.plugin_subscribers
|