mirror of
https://github.com/Unstructured-IO/unstructured.git
synced 2025-08-18 05:37:53 +00:00

* fix conflicts * add tests and clean metadata_filename in partitions * fix test_email and remove comments * make tidy/check * update changelog and version * fix tests * make tidy again
84 lines
3.0 KiB
Python
84 lines
3.0 KiB
Python
import os
|
|
import pathlib
|
|
|
|
import pytest
|
|
|
|
from unstructured.documents.elements import ListItem, NarrativeText, Title
|
|
from unstructured.partition.ppt import partition_ppt
|
|
|
|
DIRECTORY = pathlib.Path(__file__).parent.resolve()
|
|
EXAMPLE_DOCS_DIRECTORY = os.path.join(DIRECTORY, "..", "..", "example-docs")
|
|
|
|
EXPECTED_PPT_OUTPUT = [
|
|
Title(text="Adding a Bullet Slide"),
|
|
ListItem(text="Find the bullet slide layout"),
|
|
ListItem(text="Use _TextFrame.text for first bullet"),
|
|
ListItem(text="Use _TextFrame.add_paragraph() for subsequent bullets"),
|
|
NarrativeText(text="Here is a lot of text!"),
|
|
NarrativeText(text="Here is some text in a text box!"),
|
|
]
|
|
|
|
|
|
def test_partition_ppt_from_filename():
|
|
filename = os.path.join(EXAMPLE_DOCS_DIRECTORY, "fake-power-point.ppt")
|
|
elements = partition_ppt(filename=filename)
|
|
assert elements == EXPECTED_PPT_OUTPUT
|
|
for element in elements:
|
|
assert element.metadata.filename == "fake-power-point.ppt"
|
|
|
|
|
|
def test_partition_ppt_from_filename_with_metadata_filename():
|
|
filename = os.path.join(EXAMPLE_DOCS_DIRECTORY, "fake-power-point.ppt")
|
|
elements = partition_ppt(filename=filename, metadata_filename="test")
|
|
assert all(element.metadata.filename == "test" for element in elements)
|
|
|
|
|
|
def test_partition_ppt_raises_with_missing_file():
|
|
filename = os.path.join(EXAMPLE_DOCS_DIRECTORY, "doesnt-exist.ppt")
|
|
with pytest.raises(ValueError):
|
|
partition_ppt(filename=filename)
|
|
|
|
|
|
def test_partition_ppt_from_file():
|
|
filename = os.path.join(EXAMPLE_DOCS_DIRECTORY, "fake-power-point.ppt")
|
|
with open(filename, "rb") as f:
|
|
elements = partition_ppt(file=f)
|
|
assert elements == EXPECTED_PPT_OUTPUT
|
|
for element in elements:
|
|
assert element.metadata.filename is None
|
|
|
|
|
|
def test_partition_ppt_from_file_with_metadata_filename():
|
|
filename = os.path.join(EXAMPLE_DOCS_DIRECTORY, "fake-power-point.ppt")
|
|
with open(filename, "rb") as f:
|
|
elements = partition_ppt(file=f, metadata_filename="test")
|
|
assert elements == EXPECTED_PPT_OUTPUT
|
|
for element in elements:
|
|
assert element.metadata.filename == "test"
|
|
|
|
|
|
def test_partition_ppt_raises_with_both_specified():
|
|
filename = os.path.join(EXAMPLE_DOCS_DIRECTORY, "fake-power-point.ppt")
|
|
with open(filename, "rb") as f, pytest.raises(ValueError):
|
|
partition_ppt(filename=filename, file=f)
|
|
|
|
|
|
def test_partition_ppt_raises_with_neither():
|
|
with pytest.raises(ValueError):
|
|
partition_ppt()
|
|
|
|
|
|
def test_partition_ppt_from_filename_exclude_metadata():
|
|
filename = os.path.join(EXAMPLE_DOCS_DIRECTORY, "fake-power-point.ppt")
|
|
elements = partition_ppt(filename=filename, include_metadata=False)
|
|
for i in range(len(elements)):
|
|
assert elements[i].metadata.to_dict() == {}
|
|
|
|
|
|
def test_partition_ppt_from_file_exclude_metadata():
|
|
filename = os.path.join(EXAMPLE_DOCS_DIRECTORY, "fake-power-point.ppt")
|
|
with open(filename, "rb") as f:
|
|
elements = partition_ppt(file=f, include_metadata=False)
|
|
for i in range(len(elements)):
|
|
assert elements[i].metadata.to_dict() == {}
|