Phase 1 of module restructuring as outlined in docs/REFACTOR.md: New neopig/ package modules: - live.py: Live media queue (get_live_queue, emit_live_media) - state.py: AppendOnlyStateLog, state file helpers - html_utils.py: trim_html_wrapper, extract_meta_from_html - logging.py: TqdmLoggingHandler, job logging functions - backfill/: markdown and screenshot backfill operations Package features: - Lazy import of NeoPig/main from neopig.py via __getattr__ - Full backwards compatibility with existing imports - 42 new unit tests for extracted modules Total: 458 tests passing
71 lines
1.9 KiB
Python
71 lines
1.9 KiB
Python
"""
|
|
Tests for neopig.live module.
|
|
|
|
Tests live media queue functionality.
|
|
"""
|
|
|
|
import pytest
|
|
import asyncio
|
|
from unittest.mock import patch
|
|
|
|
from neopig.live import get_live_queue, emit_live_media, LIVE_MEDIA_QUEUE
|
|
|
|
|
|
class TestGetLiveQueue:
|
|
"""Test get_live_queue function."""
|
|
|
|
def setup_method(self):
|
|
# Reset global queue before each test
|
|
import neopig.live
|
|
neopig.live.LIVE_MEDIA_QUEUE = None
|
|
|
|
def test_creates_queue_on_first_call(self):
|
|
"""Test that queue is created on first call."""
|
|
queue = get_live_queue()
|
|
assert queue is not None
|
|
assert isinstance(queue, asyncio.Queue)
|
|
|
|
def test_returns_same_queue_on_subsequent_calls(self):
|
|
"""Test that same queue is returned on subsequent calls."""
|
|
queue1 = get_live_queue()
|
|
queue2 = get_live_queue()
|
|
assert queue1 is queue2
|
|
|
|
def test_queue_has_max_size(self):
|
|
"""Test that queue has maxsize of 1000."""
|
|
queue = get_live_queue()
|
|
assert queue.maxsize == 1000
|
|
|
|
|
|
class TestEmitLiveMedia:
|
|
"""Test emit_live_media function."""
|
|
|
|
def setup_method(self):
|
|
import neopig.live
|
|
neopig.live.LIVE_MEDIA_QUEUE = None
|
|
|
|
def test_emits_media_info(self):
|
|
"""Test that media info is emitted to queue."""
|
|
media_info = {'md5_hash': 'abc123', 'media_type': 'image'}
|
|
emit_live_media(media_info)
|
|
|
|
queue = get_live_queue()
|
|
assert not queue.empty()
|
|
assert queue.get_nowait() == media_info
|
|
|
|
def test_does_not_block_on_full_queue(self):
|
|
"""Test that emitting to full queue doesn't block."""
|
|
# Fill the queue
|
|
queue = get_live_queue()
|
|
for i in range(1000):
|
|
queue.put_nowait({'id': i})
|
|
|
|
# This should not raise or block
|
|
emit_live_media({'id': 'overflow'})
|
|
|
|
# Queue should still be at max size
|
|
assert queue.qsize() == 1000
|
|
|
|
|
|
if __name__ == '__main__':
|
|
pytest.main([__file__, '-v'])
|