Skip to content

Commit 9ad58a1

Browse files
committed
Migrate test_decorators.py
* Change legacy calls without PartitionRequest
1 parent 061b503 commit 9ad58a1

File tree

1 file changed

+44
-22
lines changed

1 file changed

+44
-22
lines changed

_test_unstructured_client/integration/test_decorators.py

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import requests
33
from deepdiff import DeepDiff
44
from unstructured_client import UnstructuredClient
5-
from unstructured_client.models import shared
5+
from unstructured_client.models import shared, operations
66
from unstructured_client.models.errors import HTTPValidationError
77

88
FAKE_KEY = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
@@ -49,16 +49,20 @@ def test_integration_split_pdf_has_same_output_as_non_split(
4949
# This will append .pdf to filename to fool first line of filetype detection, to simulate decoding error
5050
files.file_name += ".pdf"
5151

52-
req = shared.PartitionParameters(
52+
parameters = shared.PartitionParameters(
5353
files=files,
5454
strategy=strategy,
5555
languages=["eng"],
5656
split_pdf_page=True,
5757
split_pdf_concurrency_level=concurrency_level,
5858
)
5959

60+
req = operations.PartitionRequest(
61+
partition_parameters=parameters
62+
)
63+
6064
try:
61-
resp_split = client.general.partition(req)
65+
resp_split = client.general.partition(request=req)
6266
except (HTTPValidationError, AttributeError) as exc:
6367
if not expected_ok:
6468
assert "The file does not appear to be a valid PDF." in caplog.text
@@ -67,8 +71,13 @@ def test_integration_split_pdf_has_same_output_as_non_split(
6771
else:
6872
assert exc is None
6973

70-
req.split_pdf_page = False
71-
resp_single = client.general.partition(req)
74+
parameters.split_pdf_page = False
75+
76+
req = operations.PartitionRequest(
77+
partition_parameters=parameters
78+
)
79+
80+
resp_single = client.general.partition(request=req)
7281

7382
assert len(resp_split.elements) == len(resp_single.elements)
7483
assert resp_split.content_type == resp_single.content_type
@@ -102,14 +111,16 @@ def test_integration_split_pdf_for_file_with_no_name():
102111
file_name=" ",
103112
)
104113

105-
req = shared.PartitionParameters(
106-
files=files,
107-
strategy="fast",
108-
languages=["eng"],
109-
split_pdf_page=True,
114+
req = operations.PartitionRequest(
115+
partition_parameters=shared.PartitionParameters(
116+
files=files,
117+
strategy="fast",
118+
languages=["eng"],
119+
split_pdf_page=True,
120+
)
110121
)
111122

112-
pytest.raises(ValueError, client.general.partition, req)
123+
pytest.raises(ValueError, client.general.partition, request=req)
113124

114125

115126
@pytest.mark.parametrize("starting_page_number", [1, 100])
@@ -157,16 +168,18 @@ def test_integration_split_pdf_with_page_range(
157168
file_name=filename,
158169
)
159170

160-
req = shared.PartitionParameters(
161-
files=files,
162-
strategy="fast",
163-
split_pdf_page=True,
164-
split_pdf_page_range=page_range,
165-
starting_page_number=starting_page_number,
171+
req = operations.PartitionRequest(
172+
partition_parameters=shared.PartitionParameters(
173+
files=files,
174+
strategy="fast",
175+
split_pdf_page=True,
176+
split_pdf_page_range=page_range,
177+
starting_page_number=starting_page_number,
178+
)
166179
)
167180

168181
try:
169-
resp = client.general.partition(req)
182+
resp = client.general.partition(request=req)
170183
except ValueError as exc:
171184
assert not expected_ok
172185
assert "is out of bounds." in caplog.text
@@ -219,7 +232,7 @@ def test_integration_split_pdf_strict_mode(
219232
# This will append .pdf to filename to fool first line of filetype detection, to simulate decoding error
220233
files.file_name += ".pdf"
221234

222-
req = shared.PartitionParameters(
235+
parameters = shared.PartitionParameters(
223236
files=files,
224237
strategy=strategy,
225238
languages=["eng"],
@@ -228,8 +241,12 @@ def test_integration_split_pdf_strict_mode(
228241
split_pdf_allow_failed=allow_failed,
229242
)
230243

244+
req = operations.PartitionRequest(
245+
partition_parameters=parameters
246+
)
247+
231248
try:
232-
resp_split = client.general.partition(req)
249+
resp_split = client.general.partition(request=req)
233250
except (HTTPValidationError, AttributeError) as exc:
234251
if not expected_ok:
235252
assert "The file does not appear to be a valid PDF." in caplog.text
@@ -238,8 +255,13 @@ def test_integration_split_pdf_strict_mode(
238255
else:
239256
assert exc is None
240257

241-
req.split_pdf_page = False
242-
resp_single = client.general.partition(req)
258+
parameters.split_pdf_page = False
259+
260+
req = operations.PartitionRequest(
261+
partition_parameters=parameters
262+
)
263+
264+
resp_single = client.general.partition(request=req)
243265

244266
assert len(resp_split.elements) == len(resp_single.elements)
245267
assert resp_split.content_type == resp_single.content_type

0 commit comments

Comments
 (0)