Skip to content

Commit ed43d82

Browse files
committed
Add TU
1 parent 16776f3 commit ed43d82

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

sample-docs/password.pdf

13.8 KB
Binary file not shown.

test_unstructured_inference/inference/test_layout.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,25 @@ def mock_get_elements(self, *args, **kwargs):
302302
assert page.image is None
303303

304304

305+
@pytest.mark.slow()
306+
def test_from_file_with_password(monkeypatch, mock_final_layout):
307+
308+
doc = layout.DocumentLayout.from_file(
309+
"sample-docs/password.pdf",
310+
password="password")
311+
assert doc
312+
313+
monkeypatch.setattr(layout, "get_model",
314+
lambda x: MockLayoutModel(mock_final_layout))
315+
with patch(
316+
"unstructured_inference.inference.layout.UnstructuredObjectDetectionModel",
317+
MockLayoutModel,
318+
), open("sample-docs/password.pdf",mode="rb") as fp:
319+
doc = layout.process_data_with_model(fp, model_name="fake", password="password")
320+
assert doc
321+
322+
323+
305324
def test_from_image_file_raises_with_empty_fn():
306325
with pytest.raises(FileNotFoundError):
307326
layout.DocumentLayout.from_image_file("")

unstructured_inference/inference/layout.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ def from_image_file(
9191
detection_model: Optional[UnstructuredObjectDetectionModel] = None,
9292
element_extraction_model: Optional[UnstructuredElementExtractionModel] = None,
9393
fixed_layout: Optional[List[TextRegion]] = None,
94-
password:Optional[str] = None,
9594
**kwargs,
9695
) -> DocumentLayout:
9796
"""Creates a DocumentLayout from an image file."""
@@ -118,7 +117,6 @@ def from_image_file(
118117
detection_model=detection_model,
119118
element_extraction_model=element_extraction_model,
120119
fixed_layout=fixed_layout,
121-
password=password,
122120
**kwargs,
123121
)
124122
pages.append(page)
@@ -297,7 +295,6 @@ def from_image(
297295
detection_model: Optional[UnstructuredObjectDetectionModel] = None,
298296
element_extraction_model: Optional[UnstructuredElementExtractionModel] = None,
299297
fixed_layout: Optional[List[TextRegion]] = None,
300-
password:Optional[str] = None,
301298
):
302299
"""Creates a PageLayout from an already-loaded PIL Image."""
303300

@@ -306,7 +303,6 @@ def from_image(
306303
image=image,
307304
detection_model=detection_model,
308305
element_extraction_model=element_extraction_model,
309-
password=password,
310306
)
311307
# FIXME (yao): refactor the other methods so they all return elements like the third route
312308
if page.element_extraction_model is not None:

0 commit comments

Comments
 (0)