mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-23 04:01:02 +02:00
Fixing tests
This commit is contained in:
parent
81812ee262
commit
39681e3003
1 changed files with 15 additions and 7 deletions
|
|
@ -15,12 +15,14 @@ from trustgraph.schema import Document, TextDocument, Metadata
|
||||||
class TestPdfDecoderProcessor(IsolatedAsyncioTestCase):
|
class TestPdfDecoderProcessor(IsolatedAsyncioTestCase):
|
||||||
"""Test PDF decoder processor functionality"""
|
"""Test PDF decoder processor functionality"""
|
||||||
|
|
||||||
|
@patch('trustgraph.decoding.pdf.pdf_decoder.Consumer')
|
||||||
|
@patch('trustgraph.decoding.pdf.pdf_decoder.Producer')
|
||||||
@patch('trustgraph.base.flow_processor.FlowProcessor.__init__')
|
@patch('trustgraph.base.flow_processor.FlowProcessor.__init__')
|
||||||
async def test_processor_initialization(self, mock_flow_init):
|
async def test_processor_initialization(self, mock_flow_init, mock_producer, mock_consumer):
|
||||||
"""Test PDF decoder processor initialization"""
|
"""Test PDF decoder processor initialization"""
|
||||||
# Arrange
|
# Arrange
|
||||||
mock_flow_init.return_value = None
|
mock_flow_init.return_value = None
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
'id': 'test-pdf-decoder',
|
'id': 'test-pdf-decoder',
|
||||||
'taskgroup': AsyncMock()
|
'taskgroup': AsyncMock()
|
||||||
|
|
@ -48,9 +50,11 @@ class TestPdfDecoderProcessor(IsolatedAsyncioTestCase):
|
||||||
assert producer_spec.name == "output"
|
assert producer_spec.name == "output"
|
||||||
assert producer_spec.schema == TextDocument
|
assert producer_spec.schema == TextDocument
|
||||||
|
|
||||||
|
@patch('trustgraph.decoding.pdf.pdf_decoder.Consumer')
|
||||||
|
@patch('trustgraph.decoding.pdf.pdf_decoder.Producer')
|
||||||
@patch('trustgraph.decoding.pdf.pdf_decoder.PyPDFLoader')
|
@patch('trustgraph.decoding.pdf.pdf_decoder.PyPDFLoader')
|
||||||
@patch('trustgraph.base.flow_processor.FlowProcessor.__init__')
|
@patch('trustgraph.base.flow_processor.FlowProcessor.__init__')
|
||||||
async def test_on_message_success(self, mock_flow_init, mock_pdf_loader_class):
|
async def test_on_message_success(self, mock_flow_init, mock_pdf_loader_class, mock_producer, mock_consumer):
|
||||||
"""Test successful PDF processing"""
|
"""Test successful PDF processing"""
|
||||||
# Arrange
|
# Arrange
|
||||||
mock_flow_init.return_value = None
|
mock_flow_init.return_value = None
|
||||||
|
|
@ -109,9 +113,11 @@ class TestPdfDecoderProcessor(IsolatedAsyncioTestCase):
|
||||||
assert second_output.metadata == mock_metadata
|
assert second_output.metadata == mock_metadata
|
||||||
assert second_output.text == b"Page 2 content"
|
assert second_output.text == b"Page 2 content"
|
||||||
|
|
||||||
|
@patch('trustgraph.decoding.pdf.pdf_decoder.Consumer')
|
||||||
|
@patch('trustgraph.decoding.pdf.pdf_decoder.Producer')
|
||||||
@patch('trustgraph.decoding.pdf.pdf_decoder.PyPDFLoader')
|
@patch('trustgraph.decoding.pdf.pdf_decoder.PyPDFLoader')
|
||||||
@patch('trustgraph.base.flow_processor.FlowProcessor.__init__')
|
@patch('trustgraph.base.flow_processor.FlowProcessor.__init__')
|
||||||
async def test_on_message_empty_pdf(self, mock_flow_init, mock_pdf_loader_class):
|
async def test_on_message_empty_pdf(self, mock_flow_init, mock_pdf_loader_class, mock_producer, mock_consumer):
|
||||||
"""Test handling of empty PDF"""
|
"""Test handling of empty PDF"""
|
||||||
# Arrange
|
# Arrange
|
||||||
mock_flow_init.return_value = None
|
mock_flow_init.return_value = None
|
||||||
|
|
@ -154,9 +160,11 @@ class TestPdfDecoderProcessor(IsolatedAsyncioTestCase):
|
||||||
# Verify no output was sent
|
# Verify no output was sent
|
||||||
mock_output_flow.send.assert_not_called()
|
mock_output_flow.send.assert_not_called()
|
||||||
|
|
||||||
|
@patch('trustgraph.decoding.pdf.pdf_decoder.Consumer')
|
||||||
|
@patch('trustgraph.decoding.pdf.pdf_decoder.Producer')
|
||||||
@patch('trustgraph.decoding.pdf.pdf_decoder.PyPDFLoader')
|
@patch('trustgraph.decoding.pdf.pdf_decoder.PyPDFLoader')
|
||||||
@patch('trustgraph.base.flow_processor.FlowProcessor.__init__')
|
@patch('trustgraph.base.flow_processor.FlowProcessor.__init__')
|
||||||
async def test_on_message_unicode_content(self, mock_flow_init, mock_pdf_loader_class):
|
async def test_on_message_unicode_content(self, mock_flow_init, mock_pdf_loader_class, mock_producer, mock_consumer):
|
||||||
"""Test handling of unicode content in PDF"""
|
"""Test handling of unicode content in PDF"""
|
||||||
# Arrange
|
# Arrange
|
||||||
mock_flow_init.return_value = None
|
mock_flow_init.return_value = None
|
||||||
|
|
@ -221,8 +229,8 @@ class TestPdfDecoderProcessor(IsolatedAsyncioTestCase):
|
||||||
run()
|
run()
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
mock_launch.assert_called_once_with("pdf-decoder",
|
mock_launch.assert_called_once_with("pdf-decoder",
|
||||||
"\nSimple decoder, accepts PDF documents on input, outputs pages from the\nPDF document as text as separate output objects.\n")
|
"\nSimple decoder, accepts PDF documents on input, outputs pages from the\nPDF document as text as separate output objects.\n\nSupports both inline document data and fetching from librarian via Pulsar\nfor large documents.\n")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue