from pathlib import Path import sys import pytest sys.path.insert(0, str(Path(__file__).resolve().parents[1])) from rag.core import RAGPipelineV2 from rag.fetch import find_all_indexable_files def _pipeline() -> RAGPipelineV2: return RAGPipelineV2.__new__(RAGPipelineV2) def test_office_and_csv_extraction(tmp_path: Path) -> None: Document = pytest.importorskip('docx').Document Workbook = pytest.importorskip('openpyxl').Workbook Presentation = pytest.importorskip('pptx').Presentation pytest.importorskip('unstructured.partition.auto') docx_path = tmp_path / "sample.docx" document = Document() document.add_paragraph("DOCX multimodal acceptance 7319") document.save(docx_path) pptx_path = tmp_path / "sample.pptx" presentation = Presentation() slide = presentation.slides.add_slide(presentation.slide_layouts[6]) textbox = slide.shapes.add_textbox(0, 0, 8000000, 1000000) textbox.text = "PPTX multimodal acceptance 7319" presentation.save(pptx_path) xlsx_path = tmp_path / "sample.xlsx" workbook = Workbook() sheet = workbook.active sheet.append(["format", "value"]) sheet.append(["XLSX multimodal acceptance", 7319]) workbook.save(xlsx_path) csv_path = tmp_path / "sample.csv" csv_path.write_text( "format,value\nCSV multimodal acceptance,7319\n", encoding="utf-8", ) pipeline = _pipeline() assert "DOCX multimodal acceptance 7319" in pipeline._extract_content(str(docx_path)) assert "PPTX multimodal acceptance 7319" in pipeline._extract_content(str(pptx_path)) assert "XLSX multimodal acceptance" in pipeline._extract_content(str(xlsx_path)) assert "7319" in pipeline._extract_content(str(csv_path)) def test_multimodal_extensions_are_discovered(tmp_path: Path) -> None: extensions = (".docx", ".pptx", ".xlsx", ".csv") for extension in extensions: (tmp_path / f"sample{extension}").touch() discovered = { Path(path).suffix for path in find_all_indexable_files(str(tmp_path)) } assert set(extensions) <= discovered