feat: plugins and public api (#71)

This commit is contained in:
banteg
2026-01-09 03:23:57 +04:00
committed by GitHub
parent 16c0069aa0
commit f856338b94
32 changed files with 3135 additions and 622 deletions
+47
View File
@@ -0,0 +1,47 @@
import pytest
from takopi import commands, plugins
from takopi.config import ConfigError
from tests.plugin_fixtures import FakeEntryPoint, install_entrypoints
class DummyCommand:
id = "hello"
description = "Hello command"
async def handle(self, ctx):
_ = ctx
return None
@pytest.fixture
def command_entrypoints(monkeypatch):
entrypoints = [
FakeEntryPoint(
"hello",
"takopi.commands.hello:BACKEND",
plugins.COMMAND_GROUP,
loader=DummyCommand,
)
]
install_entrypoints(monkeypatch, entrypoints)
return entrypoints
def test_command_registry_lists_ids(command_entrypoints) -> None:
ids = commands.list_command_ids()
assert "hello" in ids
def test_command_registry_gets_command(command_entrypoints) -> None:
backend = commands.get_command("hello")
assert backend.id == "hello"
def test_command_registry_unknown(command_entrypoints) -> None:
with pytest.raises(ConfigError, match="Unknown command"):
commands.get_command("nope")
def test_command_registry_optional_missing(command_entrypoints) -> None:
assert commands.get_command("nope", required=False) is None