forked from genewildish/Mainline
feat(display): add reuse flag to Display protocol
- Add reuse parameter to Display.init() for all backends - PygameDisplay: reuse existing SDL window via class-level flag - TerminalDisplay: skip re-init when reuse=True - WebSocketDisplay: skip server start when reuse=True - SixelDisplay, KittyDisplay, NullDisplay: ignore reuse (not applicable) - MultiDisplay: pass reuse to child displays - Update benchmark.py to reuse pygame display for effect benchmarks - Add test_websocket_e2e.py with e2e marker - Register e2e marker in pyproject.toml
This commit is contained in:
@@ -155,8 +155,8 @@ class TestMultiDisplay:
|
||||
|
||||
assert multi.width == 120
|
||||
assert multi.height == 40
|
||||
mock_display1.init.assert_called_once_with(120, 40)
|
||||
mock_display2.init.assert_called_once_with(120, 40)
|
||||
mock_display1.init.assert_called_once_with(120, 40, reuse=False)
|
||||
mock_display2.init.assert_called_once_with(120, 40, reuse=False)
|
||||
|
||||
def test_show_forwards_to_all_displays(self):
|
||||
"""show forwards buffer to all displays."""
|
||||
@@ -199,3 +199,12 @@ class TestMultiDisplay:
|
||||
multi.show(["test"])
|
||||
multi.clear()
|
||||
multi.cleanup()
|
||||
|
||||
def test_init_with_reuse(self):
|
||||
"""init passes reuse flag to child displays."""
|
||||
mock_display = MagicMock()
|
||||
multi = MultiDisplay([mock_display])
|
||||
|
||||
multi.init(80, 24, reuse=True)
|
||||
|
||||
mock_display.init.assert_called_once_with(80, 24, reuse=True)
|
||||
|
||||
78
tests/test_websocket_e2e.py
Normal file
78
tests/test_websocket_e2e.py
Normal file
@@ -0,0 +1,78 @@
|
||||
"""
|
||||
End-to-end tests for WebSocket display using Playwright.
|
||||
"""
|
||||
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
class TestWebSocketE2E:
|
||||
"""End-to-end tests for WebSocket display with browser."""
|
||||
|
||||
@pytest.mark.e2e
|
||||
def test_websocket_server_starts(self):
|
||||
"""Test that WebSocket server starts and serves HTTP."""
|
||||
import threading
|
||||
|
||||
from engine.display.backends.websocket import WebSocketDisplay
|
||||
|
||||
display = WebSocketDisplay(host="127.0.0.1", port=18765)
|
||||
|
||||
server_thread = threading.Thread(target=display.start_http_server)
|
||||
server_thread.daemon = True
|
||||
server_thread.start()
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
try:
|
||||
import urllib.request
|
||||
|
||||
response = urllib.request.urlopen("http://127.0.0.1:18765", timeout=5)
|
||||
assert response.status == 200
|
||||
content = response.read().decode("utf-8")
|
||||
assert len(content) > 0
|
||||
finally:
|
||||
display.cleanup()
|
||||
time.sleep(0.5)
|
||||
|
||||
@pytest.mark.e2e
|
||||
@pytest.mark.skipif(
|
||||
not pytest.importorskip("playwright", reason="playwright not installed"),
|
||||
reason="playwright not installed",
|
||||
)
|
||||
def test_websocket_browser_connection(self):
|
||||
"""Test WebSocket connection with actual browser."""
|
||||
import threading
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
from engine.display.backends.websocket import WebSocketDisplay
|
||||
|
||||
display = WebSocketDisplay(host="127.0.0.1", port=18767)
|
||||
|
||||
server_thread = threading.Thread(target=display.start_server)
|
||||
server_thread.daemon = True
|
||||
server_thread.start()
|
||||
|
||||
http_thread = threading.Thread(target=display.start_http_server)
|
||||
http_thread.daemon = True
|
||||
http_thread.start()
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
try:
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True)
|
||||
page = browser.new_page()
|
||||
|
||||
page.goto("http://127.0.0.1:18767")
|
||||
time.sleep(0.5)
|
||||
|
||||
title = page.title()
|
||||
assert len(title) >= 0
|
||||
|
||||
browser.close()
|
||||
finally:
|
||||
display.cleanup()
|
||||
time.sleep(0.5)
|
||||
Reference in New Issue
Block a user