Spaces:
Configuration error
Configuration error
File size: 1,784 Bytes
1a27ebc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | # ============================================================================
import pytest
import asyncio
from unittest.mock import AsyncMock, MagicMock, patch
from src.document_processor import AdvancedDocumentProcessor
class TestDocumentProcessor:
"""Test suite for document processing"""
@pytest.fixture
def processor(self):
return AdvancedDocumentProcessor()
@pytest.mark.asyncio
async def test_document_processing_pipeline(self, processor):
"""Test complete document processing pipeline"""
# Mock successful processing
with patch.object(processor, 'extract_with_all_methods') as mock_extract:
mock_extract.return_value = {
'text': 'Sample document text for testing purposes.',
'confidence': 0.95,
'method': 'pymupdf'
}
result = await processor.process_document('https://example.com/test.pdf')
assert 'chunks' in result
assert 'metadata' in result
assert len(result['chunks']) > 0
@pytest.mark.asyncio
async def test_smart_chunking(self, processor):
"""Test intelligent text chunking"""
sample_text = "First sentence. Second sentence. Third sentence. Fourth sentence."
chunks = await processor.create_smart_chunks(
text=sample_text,
metadata={'confidence': 0.9},
chunk_size=50
)
assert len(chunks) > 0
assert all('chunk_id' in chunk for chunk in chunks)
assert all('content' in chunk for chunk in chunks)
assert all('metadata' in chunk for chunk in chunks)
# ============================================================================
|