"""Tests for the unified inline-article rendering (``article_rich``). Covers the follow-up that made ``pyUltroid/_core/inlineresults.py``'s ``article_rich`` delegate its block -> HTML/text rendering entirely to ``pyUltroid/_core/richmsg.py`` (the ``RichBlocks`` block model), instead of keeping a second, "deliberately minimal" renderer in ``inlineresults.py``, and dropped ``assistant/inlinestuff.py``'s ``_simple_blocks`` degradation adapter now that ``article_rich`` understands every ``RichBlocks`` block type (including ``table``/``expandable``) on its own. What must keep working, regardless of which module renders it: * a raw HTML string handed to ``article_rich``/its helpers passes through verbatim (never re-escaped or reinterpreted as a block); * plain strings inside a block list/iterable still work (no need to hand-build a dict or a :class:`RichBlocks`); * the loose dict shapes the old minimal renderer accepted -- ``{"type": "header"|"paragraph"|"code", "text": ...}`` and ``{"type": "list", "items": [...], "ordered": bool}`` -- still render; * a full :class:`RichBlocks` (including ``table()``/``expandable()``) renders correctly into the native RichMessage payload; * missing native RichMessage constructors fail loudly rather than degrading into a plain Telethon article. ``pyUltroid._core.inlineresults``/``pyUltroid._core.richmsg`` only depend on stdlib + telethon, so this imports them directly without the pyUltroid production bootstrap (the repo-root ``sys.path`` insertion lives in ``tests/conftest.py``). """ from __future__ import annotations import asyncio import pytest from telethon.tl import types import pyUltroid._core.inlineresults as inlineresults import pyUltroid._core.richmsg as richmsg from pyUltroid._core.inlineresults import ( InlineResults, _blocks_to_html, _blocks_to_text, ) from pyUltroid._core.richmsg import RichBlocks # ────────────────────────────────────────────────────────────────────────── # a minimal fake client good enough for InlineBuilder.article()/article_rich() # ────────────────────────────────────────────────────────────────────────── class _FakeClient: """Just enough client behavior for native rich inline markup -- no network.""" def build_reply_markup(self, buttons): return None async def _parse_message_text(self, text, parse_mode): # No real MarkdownV3/HTML parsing needed for these tests -- return # the text untouched with no entities, mirroring what happens when # parse_mode is falsy/unavailable. return text, [] def _run(coro): return asyncio.run(coro) # ────────────────────────────────────────────────────────────────────────── # 1. raw HTML string passes through verbatim # ────────────────────────────────────────────────────────────────────────── def test_blocks_to_html_passes_raw_html_verbatim(): raw = "

already & valid HTML

" assert _blocks_to_html(raw) == raw def test_blocks_to_text_passes_raw_html_verbatim(): raw = "

already & valid HTML

" assert _blocks_to_text(raw) == raw def test_article_rich_html_passthrough_end_to_end(): ires = InlineResults(_FakeClient()) raw = "

Title

Body & more

" result = _run(ires.article_rich("T", raw)) assert isinstance(result, types.InputBotInlineResult) rich_message = result.send_message.rich_message assert isinstance(rich_message, types.InputRichMessageHTML) assert rich_message.html == raw # ────────────────────────────────────────────────────────────────────────── # 2. plain strings inside a block list # ────────────────────────────────────────────────────────────────────────── def test_blocks_to_html_accepts_plain_strings(): html = _blocks_to_html(["Hello", "World"]) assert html == "

Hello

World

" def test_blocks_to_text_accepts_plain_strings(): text = _blocks_to_text(["Hello", "World"]) assert text == "Hello\n\nWorld" def test_blocks_to_html_escapes_plain_strings(): html = _blocks_to_html([""]) assert "