import pytest
from cpex import PluginManager
def test_missing_config_file_raises_value_error():
with pytest.raises(ValueError, match="cannot read config file"):
PluginManager("/nonexistent/path/config.yaml")
def test_malformed_yaml_raises_value_error(tmp_path):
bad_config = tmp_path / "bad.yaml"
bad_config.write_text("plugins: [\n - name: broken\n : : bad_yaml")
with pytest.raises(ValueError):
PluginManager(str(bad_config))
def test_valid_empty_config_constructs_ok(tmp_path):
empty_config = tmp_path / "empty.yaml"
empty_config.write_text("plugins: []\n")
mgr = PluginManager(str(empty_config))
assert mgr is not None
@pytest.mark.asyncio
async def test_unconvertible_payload_raises_value_error(manager: PluginManager):
with pytest.raises(ValueError):
await manager.invoke_hook("custom.hook", {"bad": object()})
@pytest.mark.asyncio
async def test_invalid_cmf_payload_raises_value_error(manager: PluginManager):
with pytest.raises(ValueError, match="not a valid MessagePayload"):
await manager.invoke_hook("cmf.tool_pre_invoke", {})