1414
1515"""End-to-end video publish/subscribe tests."""
1616
17+ from __future__ import annotations
18+
1719import asyncio
1820import os
1921import struct
20- import uuid
2122import zlib
2223from pathlib import Path
2324
2425import numpy as np
25- import pytest
2626
27- from livekit import api , rtc
27+ from livekit import rtc
28+
29+ from utils import create_token , skip_if_no_credentials , unique_room_name
2830
2931
3032VIDEO_WIDTH = 640
4143]
4244
4345
44- def skip_if_no_credentials ():
45- required_vars = ["LIVEKIT_URL" , "LIVEKIT_API_KEY" , "LIVEKIT_API_SECRET" ]
46- missing = [var for var in required_vars if not os .getenv (var )]
47- return pytest .mark .skipif (
48- bool (missing ), reason = f"Missing environment variables: { ', ' .join (missing )} "
49- )
50-
51-
52- def create_token (identity : str , room_name : str ) -> str :
53- return (
54- api .AccessToken ()
55- .with_identity (identity )
56- .with_name (identity )
57- .with_grants (
58- api .VideoGrants (
59- room_join = True ,
60- room = room_name ,
61- )
62- )
63- .to_jwt ()
64- )
65-
66-
67- def unique_room_name (base : str ) -> str :
68- return f"{ base } -{ uuid .uuid4 ().hex [:8 ]} "
69-
70-
7146def _solid_color_rgba_frame (width : int , height : int , rgb : tuple [int , int , int ]) -> rtc .VideoFrame :
7247 """Build a solid-color 640x480 RGBA `VideoFrame` for the given RGB triple."""
7348 pixels = np .empty ((height , width , 4 ), dtype = np .uint8 )
@@ -129,7 +104,7 @@ def _chunk(tag: bytes, data: bytes) -> bytes:
129104class TestVideoStreamPublishSubscribe :
130105 """End-to-end: publish a 640x480 color-cycle video and verify colors on the subscriber."""
131106
132- async def test_video_stream_publish_subscribe (self ):
107+ async def test_video_stream_publish_subscribe (self ) -> None :
133108 """Publish red/green/blue/white/black (1s each, 15fps) and verify color sequence."""
134109 url = os .environ ["LIVEKIT_URL" ]
135110 room_name = unique_room_name ("test-video-colors" )
@@ -148,7 +123,7 @@ def on_track_subscribed(
148123 track : rtc .Track ,
149124 publication : rtc .RemoteTrackPublication ,
150125 participant : rtc .RemoteParticipant ,
151- ):
126+ ) -> None :
152127 nonlocal subscribed_track
153128 if track .kind == rtc .TrackKind .KIND_VIDEO :
154129 subscribed_track = track
0 commit comments