Matt Robinson fae5f8fdde
feat: add partition_odt for open office docs (#548)
* added filetype detection for odt

* add function for partition odt documents

* add odt files to auto

* changelog and version

* docs and readme

* update installation docs

* skip tests if not supported or in docker

* import pytest

* fix docs typos
2023-05-04 19:28:08 +00:00

33 lines
1.2 KiB
Python

import os
import pathlib
import pypandoc
import pytest
from unstructured.documents.elements import Title
from unstructured.partition.odt import partition_odt
DIRECTORY = pathlib.Path(__file__).parent.resolve()
EXAMPLE_DOCS_DIRECTORY = os.path.join(DIRECTORY, "..", "..", "example-docs")
odt_not_supported = "odt" not in pypandoc.get_pandoc_formats()[0]
is_in_docker = os.path.exists("/.dockerenv")
@pytest.mark.skipif(is_in_docker, reason="Skipping this test in Docker container")
@pytest.mark.skipif(odt_not_supported, reason="odt not supported in this version of pypandoc.")
def test_partition_odt_from_filename():
filename = os.path.join(EXAMPLE_DOCS_DIRECTORY, "fake.odt")
elements = partition_odt(filename=filename)
assert elements == [Title("Lorem ipsum dolor sit amet.")]
@pytest.mark.skipif(is_in_docker, reason="Skipping this test in Docker container")
@pytest.mark.skipif(odt_not_supported, reason="odt not supported in this version of pypandoc.")
def test_partition_odt_from_file():
filename = os.path.join(EXAMPLE_DOCS_DIRECTORY, "fake.odt")
with open(filename, "rb") as f:
elements = partition_odt(file=f)
assert elements == [Title("Lorem ipsum dolor sit amet.")]