"""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("Hello") 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