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
+52 -4
View File
@@ -1,19 +1,67 @@
import pytest
from takopi import transports
from takopi import plugins, transports
from takopi.config import ConfigError
from tests.plugin_fixtures import FakeEntryPoint, install_entrypoints
def test_transport_registry_lists_telegram() -> None:
class DummyTransport:
id = "telegram"
description = "Telegram"
def check_setup(self, *args, **kwargs):
raise NotImplementedError
def interactive_setup(self, *, force: bool) -> bool:
raise NotImplementedError
def lock_token(self, *, transport_config: dict[str, object], config_path):
_ = transport_config, config_path
raise NotImplementedError
def build_and_run(
self,
*,
transport_config: dict[str, object],
config_path,
runtime,
final_notify: bool,
default_engine_override: str | None,
) -> None:
_ = (
transport_config,
config_path,
runtime,
final_notify,
default_engine_override,
)
raise NotImplementedError
@pytest.fixture
def transport_entrypoints(monkeypatch):
entrypoints = [
FakeEntryPoint(
"telegram",
"takopi.telegram.backend:telegram_backend",
plugins.TRANSPORT_GROUP,
loader=DummyTransport,
)
]
install_entrypoints(monkeypatch, entrypoints)
return entrypoints
def test_transport_registry_lists_telegram(transport_entrypoints) -> None:
ids = transports.list_transports()
assert "telegram" in ids
def test_transport_registry_gets_telegram() -> None:
def test_transport_registry_gets_telegram(transport_entrypoints) -> None:
backend = transports.get_transport("telegram")
assert backend.id == "telegram"
def test_transport_registry_unknown() -> None:
def test_transport_registry_unknown(transport_entrypoints) -> None:
with pytest.raises(ConfigError, match="Unknown transport"):
transports.get_transport("nope")