fix: Lint fixes of last tests
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
"""Tests for extraction background processor."""
|
||||
# ruff: noqa: ANN001, ANN201, PLR2004, SLF001
|
||||
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
@@ -16,7 +17,7 @@ class TestExtractionProcessor:
|
||||
# Use a custom processor instance to avoid affecting the global one
|
||||
return ExtractionProcessor()
|
||||
|
||||
def test_init(self, processor):
|
||||
def test_init(self, processor) -> None:
|
||||
"""Test processor initialization."""
|
||||
assert processor.max_concurrent > 0
|
||||
assert len(processor.running_extractions) == 0
|
||||
@@ -25,12 +26,12 @@ class TestExtractionProcessor:
|
||||
assert processor.processor_task is None
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_and_stop(self, processor):
|
||||
async def test_start_and_stop(self, processor) -> None:
|
||||
"""Test starting and stopping the processor."""
|
||||
# Mock the _process_queue method to avoid actual processing
|
||||
with patch.object(
|
||||
processor, "_process_queue", new_callable=AsyncMock,
|
||||
) as mock_process:
|
||||
):
|
||||
# Start the processor
|
||||
await processor.start()
|
||||
assert processor.processor_task is not None
|
||||
@@ -41,7 +42,7 @@ class TestExtractionProcessor:
|
||||
assert processor.processor_task.done()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_already_running(self, processor):
|
||||
async def test_start_already_running(self, processor) -> None:
|
||||
"""Test starting processor when already running."""
|
||||
with patch.object(processor, "_process_queue", new_callable=AsyncMock):
|
||||
# Start first time
|
||||
@@ -56,7 +57,7 @@ class TestExtractionProcessor:
|
||||
await processor.stop()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_queue_extraction(self, processor):
|
||||
async def test_queue_extraction(self, processor) -> None:
|
||||
"""Test queuing an extraction."""
|
||||
extraction_id = 123
|
||||
|
||||
@@ -66,7 +67,7 @@ class TestExtractionProcessor:
|
||||
assert extraction_id not in processor.running_extractions
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_queue_extraction_already_running(self, processor):
|
||||
async def test_queue_extraction_already_running(self, processor) -> None:
|
||||
"""Test queuing an extraction that's already running."""
|
||||
extraction_id = 123
|
||||
processor.running_extractions.add(extraction_id)
|
||||
@@ -75,7 +76,7 @@ class TestExtractionProcessor:
|
||||
# Should still be in running extractions
|
||||
assert extraction_id in processor.running_extractions
|
||||
|
||||
def test_get_status(self, processor):
|
||||
def test_get_status(self, processor) -> None:
|
||||
"""Test getting processor status."""
|
||||
status = processor.get_status()
|
||||
|
||||
@@ -89,7 +90,7 @@ class TestExtractionProcessor:
|
||||
assert status["currently_processing"] == 0
|
||||
assert status["available_slots"] == processor.max_concurrent
|
||||
|
||||
def test_get_status_with_running_extractions(self, processor):
|
||||
def test_get_status_with_running_extractions(self, processor) -> None:
|
||||
"""Test getting processor status with running extractions."""
|
||||
processor.running_extractions.add(123)
|
||||
processor.running_extractions.add(456)
|
||||
@@ -101,7 +102,7 @@ class TestExtractionProcessor:
|
||||
assert 123 in status["processing_ids"]
|
||||
assert 456 in status["processing_ids"]
|
||||
|
||||
def test_on_extraction_completed(self, processor):
|
||||
def test_on_extraction_completed(self, processor) -> None:
|
||||
"""Test extraction completion callback."""
|
||||
extraction_id = 123
|
||||
processor.running_extractions.add(extraction_id)
|
||||
@@ -115,7 +116,7 @@ class TestExtractionProcessor:
|
||||
# Should be removed from running extractions
|
||||
assert extraction_id not in processor.running_extractions
|
||||
|
||||
def test_on_extraction_completed_with_exception(self, processor):
|
||||
def test_on_extraction_completed_with_exception(self, processor) -> None:
|
||||
"""Test extraction completion callback with exception."""
|
||||
extraction_id = 123
|
||||
processor.running_extractions.add(extraction_id)
|
||||
@@ -130,7 +131,7 @@ class TestExtractionProcessor:
|
||||
assert extraction_id not in processor.running_extractions
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_process_single_extraction_success(self, processor):
|
||||
async def test_process_single_extraction_success(self, processor) -> None:
|
||||
"""Test processing a single extraction successfully."""
|
||||
extraction_id = 123
|
||||
|
||||
@@ -157,7 +158,7 @@ class TestExtractionProcessor:
|
||||
mock_service.process_extraction.assert_called_once_with(extraction_id)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_process_single_extraction_failure(self, processor):
|
||||
async def test_process_single_extraction_failure(self, processor) -> None:
|
||||
"""Test processing a single extraction with failure."""
|
||||
extraction_id = 123
|
||||
|
||||
@@ -183,7 +184,7 @@ class TestExtractionProcessor:
|
||||
mock_service.process_extraction.assert_called_once_with(extraction_id)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_process_pending_extractions_no_slots(self, processor):
|
||||
async def test_process_pending_extractions_no_slots(self, processor) -> None:
|
||||
"""Test processing when no slots are available."""
|
||||
# Fill all slots
|
||||
for i in range(processor.max_concurrent):
|
||||
@@ -213,7 +214,7 @@ class TestExtractionProcessor:
|
||||
assert 100 not in processor.running_extractions
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_process_pending_extractions_with_slots(self, processor):
|
||||
async def test_process_pending_extractions_with_slots(self, processor) -> None:
|
||||
"""Test processing when slots are available."""
|
||||
# Mock extraction service
|
||||
mock_service = Mock()
|
||||
@@ -230,7 +231,7 @@ class TestExtractionProcessor:
|
||||
) as mock_session_class,
|
||||
patch.object(
|
||||
processor, "_process_single_extraction", new_callable=AsyncMock,
|
||||
) as mock_process,
|
||||
),
|
||||
patch(
|
||||
"app.services.extraction_processor.ExtractionService",
|
||||
return_value=mock_service,
|
||||
@@ -254,7 +255,7 @@ class TestExtractionProcessor:
|
||||
assert mock_create_task.call_count == 2
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_process_pending_extractions_respect_limit(self, processor):
|
||||
async def test_process_pending_extractions_respect_limit(self, processor) -> None:
|
||||
"""Test that processing respects concurrency limit."""
|
||||
# Set max concurrent to 1 for this test
|
||||
processor.max_concurrent = 1
|
||||
@@ -275,7 +276,7 @@ class TestExtractionProcessor:
|
||||
) as mock_session_class,
|
||||
patch.object(
|
||||
processor, "_process_single_extraction", new_callable=AsyncMock,
|
||||
) as mock_process,
|
||||
),
|
||||
patch(
|
||||
"app.services.extraction_processor.ExtractionService",
|
||||
return_value=mock_service,
|
||||
|
||||
Reference in New Issue
Block a user