Add process controls and restart command

This commit is contained in:
Azimkin
2026-08-28 23:25:20 +02:00
parent 12434ec557
commit d3c02ca203
14 changed files with 358 additions and 4 deletions

View File

@@ -0,0 +1,24 @@
from __future__ import annotations
import unittest
from app.pyrogram_compat import install_kurigram_compat
class KurigramCompatTests(unittest.IsolatedAsyncioTestCase):
async def test_nested_hashtag_is_parsed_without_lstrip_crash(self) -> None:
from pyrogram import raw
from pyrogram.types.messages_and_media.rich_text import RichText
install_kurigram_compat()
value = raw.types.TextHashtag(
text=raw.types.TextBold(text=raw.types.TextPlain(text="#tag"))
)
parsed = await RichText._parse(None, value)
self.assertEqual(parsed.hashtag, "tag")
self.assertEqual(parsed.text.text, "#tag")
if __name__ == "__main__":
unittest.main()

View File

@@ -0,0 +1,23 @@
from __future__ import annotations
import os
import signal
import unittest
from unittest.mock import AsyncMock, patch
from app.commands.builtins import restart
class RestartCommandTests(unittest.IsolatedAsyncioTestCase):
async def test_restart_confirms_then_stops_current_process(self) -> None:
ctx = type("Context", (), {"reply": AsyncMock()})()
with patch("app.commands.builtins.os.kill") as kill:
await restart(ctx)
ctx.reply.assert_awaited_once_with("Stopping bot process for restart")
kill.assert_called_once_with(os.getpid(), signal.SIGTERM)
if __name__ == "__main__":
unittest.main()