Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for chunking strategies #212

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -12,3 +12,4 @@ __pycache__/
.idea/
openapi.json
openapi_client.json
.env
44 changes: 43 additions & 1 deletion _test_unstructured_client/integration/test_decorators.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@

import httpx
import json
import os
import pytest
import requests
from deepdiff import DeepDiff
@@ -19,7 +20,7 @@
from unstructured_client._hooks.custom import form_utils
from unstructured_client._hooks.custom import split_pdf_hook

FAKE_KEY = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
FAKE_KEY = os.getenv("UNSTRUCTURED_API_KEY") or "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"


@pytest.mark.parametrize("concurrency_level", [1, 2, 5])
@@ -472,3 +473,44 @@ async def mock_send(_, request: httpx.Request, **kwargs):
assert mock_endpoint_called

assert res.status_code == 200


@pytest.mark.parametrize(
("filename", "chunking_strategy", "expected_elements_num"),
[
# -- Paid strategy --
("_sample_docs/layout-parser-paper.pdf", "by_page", 16), # 16 pages, 133 elements w/o chunking
("_sample_docs/layout-parser-paper.pdf", shared.ChunkingStrategy.BY_PAGE, 16),
# -- Open source strategy --
("_sample_docs/layout-parser-paper.pdf", "by_title", -1), # unsure what the correct number is atm
("_sample_docs/layout-parser-paper.pdf", shared.ChunkingStrategy.BY_TITLE, -1),
],
)
def test_chunking(
filename: str,
chunking_strategy: str| shared.ChunkingStrategy,
expected_elements_num: int,
):

client = UnstructuredClient(api_key_auth=FAKE_KEY)

with open(filename, "rb") as f:
files = shared.Files(
content=f.read(),
file_name=filename,
)

parameters = shared.PartitionParameters(
files=files,
chunking_strategy=chunking_strategy, # type: ignore
split_pdf_page=False, # -- Testing splitting as potential issue
)

req = operations.PartitionRequest(
partition_parameters=parameters
)

resp = client.general.partition(request=req)
assert len(resp.elements) == expected_elements_num
assert all(element.get("type") == "CompositeElement" for element in resp.elements)

Loading
Oops, something went wrong.