Split monolithic scroll.py into focused modules: - viewport.py: terminal size (tw/th), ANSI positioning helpers - frame.py: FrameTimer class, scroll step calculation - layers.py: message overlay, ticker zone, firehose rendering - scroll.py: simplified orchestrator, imports from new modules Add stream controller and event types for future event-driven architecture: - controller.py: StreamController for source initialization and stream lifecycle - events.py: EventType enum and event dataclasses (HeadlineEvent, FrameTickEvent, etc.) Added tests for new modules: - test_viewport.py: 8 tests for viewport utilities - test_frame.py: 10 tests for frame timing - test_layers.py: 13 tests for layer compositing - test_events.py: 11 tests for event types - test_controller.py: 6 tests for stream controller This enables: - Testable chunks with clear responsibilities - Reusable viewport utilities across modules - Better separation of concerns in render pipeline - Foundation for future event-driven architecture Also includes Phase 1 documentation updates in code comments.
65 lines
1.6 KiB
Python
65 lines
1.6 KiB
Python
"""
|
|
Tests for engine.viewport module.
|
|
"""
|
|
|
|
from engine import viewport
|
|
|
|
|
|
class TestViewportTw:
|
|
"""Tests for tw() function."""
|
|
|
|
def test_tw_returns_int(self):
|
|
"""tw() returns an integer."""
|
|
result = viewport.tw()
|
|
assert isinstance(result, int)
|
|
|
|
def test_tw_positive(self):
|
|
"""tw() returns a positive value."""
|
|
assert viewport.tw() > 0
|
|
|
|
|
|
class TestViewportTh:
|
|
"""Tests for th() function."""
|
|
|
|
def test_th_returns_int(self):
|
|
"""th() returns an integer."""
|
|
result = viewport.th()
|
|
assert isinstance(result, int)
|
|
|
|
def test_th_positive(self):
|
|
"""th() returns a positive value."""
|
|
assert viewport.th() > 0
|
|
|
|
|
|
class TestViewportMoveTo:
|
|
"""Tests for move_to() function."""
|
|
|
|
def test_move_to_format(self):
|
|
"""move_to() returns correctly formatted ANSI escape."""
|
|
result = viewport.move_to(5, 10)
|
|
assert result == "\033[5;10H"
|
|
|
|
def test_move_to_default_col(self):
|
|
"""move_to() defaults to column 1."""
|
|
result = viewport.move_to(5)
|
|
assert result == "\033[5;1H"
|
|
|
|
|
|
class TestViewportClearScreen:
|
|
"""Tests for clear_screen() function."""
|
|
|
|
def test_clear_screen_format(self):
|
|
"""clear_screen() returns clear screen ANSI escape."""
|
|
result = viewport.clear_screen()
|
|
assert "\033[2J" in result
|
|
assert "\033[H" in result
|
|
|
|
|
|
class TestViewportClearLine:
|
|
"""Tests for clear_line() function."""
|
|
|
|
def test_clear_line_format(self):
|
|
"""clear_line() returns clear line ANSI escape."""
|
|
result = viewport.clear_line()
|
|
assert result == "\033[K"
|