- Move effects_plugins/ to engine/effects/plugins/ - Update imports in engine/app.py - Update imports in all test files - Follows capability-based deps architecture Closes #27
101 lines
2.8 KiB
Python
101 lines
2.8 KiB
Python
"""
|
|
Tests for engine.benchmark module - performance regression tests.
|
|
"""
|
|
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
from engine.display import NullDisplay
|
|
|
|
|
|
class TestBenchmarkNullDisplay:
|
|
"""Performance tests for NullDisplay - regression tests."""
|
|
|
|
@pytest.mark.benchmark
|
|
def test_null_display_minimum_fps(self):
|
|
"""NullDisplay should meet minimum performance threshold."""
|
|
import time
|
|
|
|
display = NullDisplay()
|
|
display.init(80, 24)
|
|
buffer = ["x" * 80 for _ in range(24)]
|
|
|
|
iterations = 1000
|
|
start = time.perf_counter()
|
|
for _ in range(iterations):
|
|
display.show(buffer)
|
|
elapsed = time.perf_counter() - start
|
|
|
|
fps = iterations / elapsed
|
|
min_fps = 20000
|
|
|
|
assert fps >= min_fps, f"NullDisplay FPS {fps:.0f} below minimum {min_fps}"
|
|
|
|
@pytest.mark.benchmark
|
|
def test_effects_minimum_throughput(self):
|
|
"""Effects should meet minimum processing throughput."""
|
|
import time
|
|
|
|
from engine.effects import EffectContext, get_registry
|
|
from engine.effects.plugins import discover_plugins
|
|
|
|
discover_plugins()
|
|
registry = get_registry()
|
|
effect = registry.get("noise")
|
|
assert effect is not None, "Noise effect should be registered"
|
|
|
|
buffer = ["x" * 80 for _ in range(24)]
|
|
ctx = EffectContext(
|
|
terminal_width=80,
|
|
terminal_height=24,
|
|
scroll_cam=0,
|
|
ticker_height=20,
|
|
mic_excess=0.0,
|
|
grad_offset=0.0,
|
|
frame_number=0,
|
|
has_message=False,
|
|
)
|
|
|
|
iterations = 500
|
|
start = time.perf_counter()
|
|
for _ in range(iterations):
|
|
effect.process(buffer, ctx)
|
|
elapsed = time.perf_counter() - start
|
|
|
|
fps = iterations / elapsed
|
|
min_fps = 10000
|
|
|
|
assert fps >= min_fps, (
|
|
f"Effect processing FPS {fps:.0f} below minimum {min_fps}"
|
|
)
|
|
|
|
|
|
class TestBenchmarkWebSocketDisplay:
|
|
"""Performance tests for WebSocketDisplay."""
|
|
|
|
@pytest.mark.benchmark
|
|
def test_websocket_display_minimum_fps(self):
|
|
"""WebSocketDisplay should meet minimum performance threshold."""
|
|
import time
|
|
|
|
with patch("engine.display.backends.websocket.websockets", None):
|
|
from engine.display import WebSocketDisplay
|
|
|
|
display = WebSocketDisplay()
|
|
display.init(80, 24)
|
|
buffer = ["x" * 80 for _ in range(24)]
|
|
|
|
iterations = 500
|
|
start = time.perf_counter()
|
|
for _ in range(iterations):
|
|
display.show(buffer)
|
|
elapsed = time.perf_counter() - start
|
|
|
|
fps = iterations / elapsed
|
|
min_fps = 10000
|
|
|
|
assert fps >= min_fps, (
|
|
f"WebSocketDisplay FPS {fps:.0f} below minimum {min_fps}"
|
|
)
|