Refactor test files for improved readability and consistency
- Removed unnecessary blank lines and adjusted formatting in test files. - Ensured consistent use of commas in function calls and assertions across various test cases. - Updated import statements for better organization and clarity. - Enhanced mock setups in tests for better isolation and reliability. - Improved assertions to follow a consistent style for better readability.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
"""Tests for extraction background processor."""
|
||||
|
||||
import asyncio
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
@@ -30,7 +29,7 @@ class TestExtractionProcessor:
|
||||
"""Test starting and stopping the processor."""
|
||||
# Mock the _process_queue method to avoid actual processing
|
||||
with patch.object(
|
||||
processor, "_process_queue", new_callable=AsyncMock
|
||||
processor, "_process_queue", new_callable=AsyncMock,
|
||||
) as mock_process:
|
||||
# Start the processor
|
||||
await processor.start()
|
||||
@@ -138,12 +137,12 @@ class TestExtractionProcessor:
|
||||
# Mock the extraction service
|
||||
mock_service = Mock()
|
||||
mock_service.process_extraction = AsyncMock(
|
||||
return_value={"status": "completed", "id": extraction_id}
|
||||
return_value={"status": "completed", "id": extraction_id},
|
||||
)
|
||||
|
||||
with (
|
||||
patch(
|
||||
"app.services.extraction_processor.AsyncSession"
|
||||
"app.services.extraction_processor.AsyncSession",
|
||||
) as mock_session_class,
|
||||
patch(
|
||||
"app.services.extraction_processor.ExtractionService",
|
||||
@@ -168,7 +167,7 @@ class TestExtractionProcessor:
|
||||
|
||||
with (
|
||||
patch(
|
||||
"app.services.extraction_processor.AsyncSession"
|
||||
"app.services.extraction_processor.AsyncSession",
|
||||
) as mock_session_class,
|
||||
patch(
|
||||
"app.services.extraction_processor.ExtractionService",
|
||||
@@ -193,12 +192,12 @@ class TestExtractionProcessor:
|
||||
# Mock extraction service
|
||||
mock_service = Mock()
|
||||
mock_service.get_pending_extractions = AsyncMock(
|
||||
return_value=[{"id": 100, "status": "pending"}]
|
||||
return_value=[{"id": 100, "status": "pending"}],
|
||||
)
|
||||
|
||||
with (
|
||||
patch(
|
||||
"app.services.extraction_processor.AsyncSession"
|
||||
"app.services.extraction_processor.AsyncSession",
|
||||
) as mock_session_class,
|
||||
patch(
|
||||
"app.services.extraction_processor.ExtractionService",
|
||||
@@ -222,15 +221,15 @@ class TestExtractionProcessor:
|
||||
return_value=[
|
||||
{"id": 100, "status": "pending"},
|
||||
{"id": 101, "status": "pending"},
|
||||
]
|
||||
],
|
||||
)
|
||||
|
||||
with (
|
||||
patch(
|
||||
"app.services.extraction_processor.AsyncSession"
|
||||
"app.services.extraction_processor.AsyncSession",
|
||||
) as mock_session_class,
|
||||
patch.object(
|
||||
processor, "_process_single_extraction", new_callable=AsyncMock
|
||||
processor, "_process_single_extraction", new_callable=AsyncMock,
|
||||
) as mock_process,
|
||||
patch(
|
||||
"app.services.extraction_processor.ExtractionService",
|
||||
@@ -267,15 +266,15 @@ class TestExtractionProcessor:
|
||||
{"id": 100, "status": "pending"},
|
||||
{"id": 101, "status": "pending"},
|
||||
{"id": 102, "status": "pending"},
|
||||
]
|
||||
],
|
||||
)
|
||||
|
||||
with (
|
||||
patch(
|
||||
"app.services.extraction_processor.AsyncSession"
|
||||
"app.services.extraction_processor.AsyncSession",
|
||||
) as mock_session_class,
|
||||
patch.object(
|
||||
processor, "_process_single_extraction", new_callable=AsyncMock
|
||||
processor, "_process_single_extraction", new_callable=AsyncMock,
|
||||
) as mock_process,
|
||||
patch(
|
||||
"app.services.extraction_processor.ExtractionService",
|
||||
|
||||
Reference in New Issue
Block a user