mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-14 14:12:44 +00:00
33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
"""Shared fixtures for telegram plugin tests.
|
|
|
|
Provides the ``_ensure_telegram_mock`` helper that guarantees a minimal mock
|
|
of the ``telegram`` package is registered in :data:`sys.modules` **before**
|
|
any test file triggers ``from hermes_agent_telegram import ...``.
|
|
"""
|
|
|
|
import sys
|
|
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
|
|
|
|
def _ensure_telegram_mock():
|
|
if "telegram" in sys.modules and hasattr(sys.modules["telegram"], "__file__"):
|
|
return
|
|
mod = MagicMock()
|
|
mod.ext.ContextTypes.DEFAULT_TYPE = type(None)
|
|
mod.constants.ParseMode.MARKDOWN_V2 = "MarkdownV2"
|
|
mod.constants.ChatType.GROUP = "group"
|
|
mod.constants.ChatType.SUPERGROUP = "supergroup"
|
|
mod.constants.ChatType.CHANNEL = "channel"
|
|
mod.constants.ChatType.PRIVATE = "private"
|
|
# Prevent pytest from interpreting auto-generated mock attributes as
|
|
# plugin specs. Without this, ``mod.pytest_plugins`` returns a child
|
|
# MagicMock which trips _get_plugin_specs_as_list().
|
|
mod.pytest_plugins = None
|
|
for name in ("telegram", "telegram.ext", "telegram.constants", "telegram.request"):
|
|
sys.modules.setdefault(name, mod)
|
|
|
|
|
|
# Auto-apply at collection time so every test file sees the mock.
|
|
_ensure_telegram_mock()
|