- Add pytest test suite across all modules (config, database, file_processor, ai_processor, api, scheduler, monitoring, ftp_server) - 145 tests covering normal paths, error handling, edge cases - Mock external dependencies (AI endpoint, requests, pyftpdlib) - 95% code coverage with fail-under=90 threshold in CI - Update CI workflow to run pytest with coverage enforcement - Add pyproject.toml with pytest/coverage configuration
42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
"""Extended tests for file_processor: PDF, XML extraction."""
|
|
|
|
import pytest
|
|
from unittest.mock import patch, MagicMock
|
|
|
|
from factsdb.file_processor import FileProcessor
|
|
|
|
|
|
@pytest.fixture
|
|
def processor():
|
|
return FileProcessor()
|
|
|
|
|
|
class TestPdfExtraction:
|
|
def test_pdf_success(self, processor, tmp_path):
|
|
f = tmp_path / "test.pdf"
|
|
f.write_bytes(b"%PDF-1.4 fake pdf content")
|
|
with patch("pdfminer.high_level.extract_text", return_value="PDF content here"):
|
|
text = processor.extract_text_from_file(str(f))
|
|
assert text == "PDF content here"
|
|
|
|
def test_pdf_failure(self, processor, tmp_path):
|
|
f = tmp_path / "test.pdf"
|
|
f.write_bytes(b"%PDF-1.4 fake pdf content")
|
|
with patch("pdfminer.high_level.extract_text", side_effect=Exception("parse error")):
|
|
with pytest.raises(Exception, match="PDF extraction failed"):
|
|
processor.extract_text_from_file(str(f))
|
|
|
|
|
|
class TestXmlExtraction:
|
|
def test_xml_file(self, processor, tmp_path):
|
|
f = tmp_path / "test.xml"
|
|
f.write_text("<root><item>Hello</item></root>")
|
|
text = processor.extract_text_from_file(str(f))
|
|
assert "Hello" in text
|
|
|
|
def test_json_invalid(self, processor, tmp_path):
|
|
f = tmp_path / "test.json"
|
|
f.write_text("{invalid json")
|
|
text = processor.extract_text_from_file(str(f))
|
|
assert "invalid json" in text
|