test: cover subprocess cleanup and markdown entities
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
from codex_telegram_bridge.rendering import render_markdown
|
||||||
|
|
||||||
|
|
||||||
|
def test_render_markdown_basic_entities() -> None:
|
||||||
|
text, entities = render_markdown("**bold** and `code`")
|
||||||
|
|
||||||
|
assert text == "bold and code\n\n"
|
||||||
|
assert entities == [
|
||||||
|
{"type": "bold", "offset": 0, "length": 4},
|
||||||
|
{"type": "code", "offset": 9, "length": 4},
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_render_markdown_code_fence_language_is_string() -> None:
|
||||||
|
text, entities = render_markdown("```py\nprint('x')\n```")
|
||||||
|
|
||||||
|
assert text == "print('x')\n\n"
|
||||||
|
assert entities is not None
|
||||||
|
assert any(
|
||||||
|
e.get("type") == "pre" and e.get("language") == "py" for e in entities
|
||||||
|
)
|
||||||
|
assert any(e.get("type") == "code" for e in entities)
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import asyncio
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from codex_telegram_bridge import exec_bridge
|
||||||
|
|
||||||
|
|
||||||
|
def test_manage_subprocess_kills_when_terminate_times_out(monkeypatch) -> None:
|
||||||
|
async def fake_wait_for(awaitable, *args, **kwargs):
|
||||||
|
if hasattr(awaitable, "close"):
|
||||||
|
awaitable.close()
|
||||||
|
elif hasattr(awaitable, "cancel"):
|
||||||
|
awaitable.cancel()
|
||||||
|
raise asyncio.TimeoutError
|
||||||
|
|
||||||
|
monkeypatch.setattr(exec_bridge.asyncio, "wait_for", fake_wait_for)
|
||||||
|
|
||||||
|
async def run() -> int | None:
|
||||||
|
async with exec_bridge.manage_subprocess(
|
||||||
|
sys.executable,
|
||||||
|
"-c",
|
||||||
|
"import signal, time; signal.signal(signal.SIGTERM, signal.SIG_IGN); time.sleep(10)",
|
||||||
|
) as proc:
|
||||||
|
assert proc.returncode is None
|
||||||
|
return proc.returncode
|
||||||
|
|
||||||
|
rc = asyncio.run(run())
|
||||||
|
|
||||||
|
assert rc is not None
|
||||||
|
assert rc != 0
|
||||||
Reference in New Issue
Block a user