2
2
import requests
3
3
from deepdiff import DeepDiff
4
4
from unstructured_client import UnstructuredClient
5
- from unstructured_client .models import shared
5
+ from unstructured_client .models import shared , operations
6
6
from unstructured_client .models .errors import HTTPValidationError
7
7
8
8
FAKE_KEY = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
@@ -49,16 +49,20 @@ def test_integration_split_pdf_has_same_output_as_non_split(
49
49
# This will append .pdf to filename to fool first line of filetype detection, to simulate decoding error
50
50
files .file_name += ".pdf"
51
51
52
- req = shared .PartitionParameters (
52
+ parameters = shared .PartitionParameters (
53
53
files = files ,
54
54
strategy = strategy ,
55
55
languages = ["eng" ],
56
56
split_pdf_page = True ,
57
57
split_pdf_concurrency_level = concurrency_level ,
58
58
)
59
59
60
+ req = operations .PartitionRequest (
61
+ partition_parameters = parameters
62
+ )
63
+
60
64
try :
61
- resp_split = client .general .partition (req )
65
+ resp_split = client .general .partition (request = req )
62
66
except (HTTPValidationError , AttributeError ) as exc :
63
67
if not expected_ok :
64
68
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(
67
71
else :
68
72
assert exc is None
69
73
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 )
72
81
73
82
assert len (resp_split .elements ) == len (resp_single .elements )
74
83
assert resp_split .content_type == resp_single .content_type
@@ -102,14 +111,16 @@ def test_integration_split_pdf_for_file_with_no_name():
102
111
file_name = " " ,
103
112
)
104
113
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
+ )
110
121
)
111
122
112
- pytest .raises (ValueError , client .general .partition , req )
123
+ pytest .raises (ValueError , client .general .partition , request = req )
113
124
114
125
115
126
@pytest .mark .parametrize ("starting_page_number" , [1 , 100 ])
@@ -157,16 +168,18 @@ def test_integration_split_pdf_with_page_range(
157
168
file_name = filename ,
158
169
)
159
170
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
+ )
166
179
)
167
180
168
181
try :
169
- resp = client .general .partition (req )
182
+ resp = client .general .partition (request = req )
170
183
except ValueError as exc :
171
184
assert not expected_ok
172
185
assert "is out of bounds." in caplog .text
@@ -219,7 +232,7 @@ def test_integration_split_pdf_strict_mode(
219
232
# This will append .pdf to filename to fool first line of filetype detection, to simulate decoding error
220
233
files .file_name += ".pdf"
221
234
222
- req = shared .PartitionParameters (
235
+ parameters = shared .PartitionParameters (
223
236
files = files ,
224
237
strategy = strategy ,
225
238
languages = ["eng" ],
@@ -228,8 +241,12 @@ def test_integration_split_pdf_strict_mode(
228
241
split_pdf_allow_failed = allow_failed ,
229
242
)
230
243
244
+ req = operations .PartitionRequest (
245
+ partition_parameters = parameters
246
+ )
247
+
231
248
try :
232
- resp_split = client .general .partition (req )
249
+ resp_split = client .general .partition (request = req )
233
250
except (HTTPValidationError , AttributeError ) as exc :
234
251
if not expected_ok :
235
252
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(
238
255
else :
239
256
assert exc is None
240
257
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 )
243
265
244
266
assert len (resp_split .elements ) == len (resp_single .elements )
245
267
assert resp_split .content_type == resp_single .content_type
0 commit comments