Spaces:
Sleeping
Sleeping
File size: 1,468 Bytes
2d25973 | 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 50 51 52 53 | import sys
import os
import io
# Add parent to path for imports
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from src.utils.extractor import extract_universal_text
def create_mock_file(name, content_bytes):
f = io.BytesIO(content_bytes)
f.name = name
return f
def test_markdown():
print("Testing Markdown extraction...")
content = b"# Hello Markdown\nThis is a test."
file = create_mock_file("test.md", content)
text = extract_universal_text(file)
print(f"Extracted: {text.strip()}")
assert "Hello Markdown" in text
def test_docx():
print("Testing DOCX extraction...")
import docx
doc = docx.Document()
doc.add_paragraph("Hello from DOCX")
f = io.BytesIO()
doc.save(f)
file = create_mock_file("test.docx", f.getvalue())
text = extract_universal_text(file)
print(f"Extracted: {text.strip()}")
assert "Hello from DOCX" in text
def test_pptx():
print("Testing PPTX extraction...")
import pptx
prs = pptx.Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[0])
slide.shapes.title.text = "Hello from PPTX"
f = io.BytesIO()
prs.save(f)
file = create_mock_file("test.pptx", f.getvalue())
text = extract_universal_text(file)
print(f"Extracted: {text.strip()}")
assert "Hello from PPTX" in text
if __name__ == "__main__":
test_markdown()
test_docx()
test_pptx()
print("All tests passed!")
|