testing.sse

Page actions AI-ready formats and sharing
Open LLM text
Share with AI
Ask Claude Ask ChatGPT Ask Gemini Ask Copilot

SSE testing utilities.

Provides structured parsing of Server-Sent Events responses for use in test assertions.

SSE testing utilities.

Provides structured parsing of Server-Sent Events responses for use in test assertions.

testing.sse

Name Type Default Description
type
qualified_name
element_type
description
source_file
line_number
is_autodoc
autodoc_element
_autodoc_template
_autodoc_url_path
_autodoc_page_type
title
doc_content_hash

Symbols on this page

SSETestResult
class

Collected events from an SSE endpoint.

Returned byTestClient.sse()after the connection closes.

parse_sse_frames
function
def parse_sse_frames(raw: str) -> tuple[list[SSEEvent], int]

Parse raw SSE text into structured events and heartbeat count.

Splits on double-newline boundaries. Each block is parsed into an SSEEvent. Comment lines (starting with :) are counted as heartbeats if they contain "heartbeat".

Parameters

Name Type Default Description
raw str
_SseAttrExtractor
class

Collect htmx-sse wiring attributes from rendered HTML.

extract_sse_attrs
function
def extract_sse_attrs(html: str) -> tuple[list[str], set[str]]

Return(connection URLs, legacy sse-swap event names)from HTML.

Connection URLs include both htmx 2sse-connectand htmx 4 hx-sse:connectvalues. The second item remains the legacy named-swap set for backward compatibility; htmx 4 uses unnamed HTML and partials.

Parameters

Name Type Default Description
html str
_SsePayloadExtractor
class

Collect bounded htmx 4 target metadata from one SSE data payload.

assert_sse_wired
function async
async def assert_sse_wired(client: TestClient, page_path: str, sse_path: str, *, max_events: int = 5) -> None

Cross-check version-aware SSE wiring between the page and the stream.

Htmx 2 checks namedsse-swaplisteners against emitted event names. Htmx 4 selects the fetch-stream request dialect and checks connection, partial, and OOB targets against rendered page IDs.

Stream-emitted events that no listener consumes are allowed — streams may emitstatus/closemetadata that is not a swap target.

Parameters

Name Type Default Description
client TestClient
page_path str
sse_path str
max_events int 5

View source · /home/runner/work/chirp/chirp/site/../src/chirp/testing/sse.py:1