Skip to content

Commit 318065b

Browse files
committed
Update tests to use is_extracted
1 parent 3c343db commit 318065b

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

test_unstructured_inference/inference/test_layout.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def mock_initial_layout():
3434
6,
3535
8,
3636
text="A very repetitive narrative. " * 10,
37-
text_source="Mock",
37+
is_extracted=True,
3838
)
3939

4040
title_block = EmbeddedTextRegion.from_coords(
@@ -43,7 +43,7 @@ def mock_initial_layout():
4343
3,
4444
4,
4545
text="A Catchy Title",
46-
text_source="Mock",
46+
is_extracted=True,
4747
)
4848

4949
return [text_block, title_block]

test_unstructured_inference/inference/test_layout_element.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from unstructured_inference.inference.layoutelement import LayoutElement, TextRegion
2-
from unstructured_inference.constants import Source, TextSource
2+
from unstructured_inference.constants import Source
33

44

55
def test_layout_element_to_dict(mock_layout_element):
66
expected = {
77
"coordinates": ((100, 100), (100, 300), (300, 300), (300, 100)),
88
"text": "Sample text",
9-
"text_source": None,
9+
"is_extracted": None,
1010
"type": "Text",
1111
"prob": None,
1212
"source": None,
@@ -28,7 +28,7 @@ def test_layoutelement_inheritance_works_correctly():
2828

2929
# Create a TextRegion with both source and text_source
3030
region = TextRegion.from_coords(
31-
0, 0, 10, 10, text="test", source=Source.YOLOX, text_source=TextSource.OCR
31+
0, 0, 10, 10, text="test", source=Source.YOLOX, is_extracted=True
3232
)
3333

3434
# Convert to LayoutElement
@@ -37,13 +37,13 @@ def test_layoutelement_inheritance_works_correctly():
3737
# Check that both properties are preserved
3838
assert element.source == Source.YOLOX, "LayoutElement should inherit source from TextRegion"
3939
assert (
40-
element.text_source == TextSource.OCR
41-
), "LayoutElement should inherit text_source from TextRegion"
40+
element.is_extracted
41+
), "LayoutElement should inherit is_extracted from TextRegion"
4242

4343
# Check that to_dict() works correctly
4444
d = element.to_dict()
4545
assert d["source"] == Source.YOLOX
46-
assert d["text_source"] == TextSource.OCR
46+
assert d["is_extracted"]
4747

4848
# Check that we can set source directly on LayoutElement
4949
element.source = Source.DETECTRON2_ONNX

test_unstructured_inference/test_elements.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy as np
66
import pytest
77

8-
from unstructured_inference.constants import Source, TextSource
8+
from unstructured_inference.constants import Source
99
from unstructured_inference.inference import elements
1010
from unstructured_inference.inference.elements import (
1111
Rectangle,
@@ -410,8 +410,8 @@ def test_layoutelements_from_list_no_elements():
410410

411411
def test_textregions_from_list_no_elements():
412412
back = TextRegions.from_list(regions=[])
413-
assert back.text_sources.size == 0
414-
assert back.text_source is None
413+
assert back.is_extracted_array.size == 0
414+
assert back.is_extracted is None
415415
assert back.element_coords.size == 0
416416

417417

@@ -456,8 +456,8 @@ def test_layoutelements_concatenate():
456456
]
457457
),
458458
texts=np.array(["0", "1", "2", "3", "4"]),
459-
text_sources=np.array([TextSource.OCR] * 5),
460-
text_source=TextSource.OCR,
459+
is_extracted_array=np.array([True] * 5),
460+
is_extracted=True,
461461
),
462462
LayoutElements(
463463
element_coords=np.array(
@@ -472,8 +472,8 @@ def test_layoutelements_concatenate():
472472
texts=np.array(["0", "1", "2", "3", "4"]),
473473
sources=np.array([Source.YOLOX] * 5),
474474
source=Source.YOLOX,
475-
text_sources=np.array([TextSource.OCR] * 5),
476-
text_source=TextSource.OCR,
475+
is_extracted_array=np.array([] * 5),
476+
is_extracted=True,
477477
element_probs=np.array([0.0, 0.1, 0.2, 0.3, 0.4]),
478478
),
479479
],
@@ -496,7 +496,7 @@ def test_textregions_from_list_collects_sources():
496496

497497
regions = [
498498
TextRegion.from_coords(
499-
0, 0, 10, 10, text="first", source=Source.YOLOX, text_source=TextSource.OCR
499+
0, 0, 10, 10, text="first", source=Source.YOLOX, is_extracted=True
500500
),
501501
TextRegion.from_coords(
502502
10,
@@ -505,7 +505,7 @@ def test_textregions_from_list_collects_sources():
505505
20,
506506
text="second",
507507
source=Source.DETECTRON2_ONNX,
508-
text_source=TextSource.EXTRACTED,
508+
is_extracted=True,
509509
),
510510
]
511511

@@ -532,7 +532,7 @@ def test_textregions_iter_elements_preserves_source():
532532

533533
regions = [
534534
TextRegion.from_coords(
535-
0, 0, 10, 10, text="first", source=Source.YOLOX, text_source=TextSource.OCR
535+
0, 0, 10, 10, text="first", source=Source.YOLOX, is_extracted=True
536536
),
537537
]
538538
text_regions = TextRegions.from_list(regions)
@@ -549,7 +549,7 @@ def test_textregions_slice_preserves_sources():
549549

550550
regions = [
551551
TextRegion.from_coords(
552-
0, 0, 10, 10, text="first", source=Source.YOLOX, text_source=TextSource.OCR
552+
0, 0, 10, 10, text="first", source=Source.YOLOX, is_extracted=True
553553
),
554554
TextRegion.from_coords(
555555
10,
@@ -558,7 +558,7 @@ def test_textregions_slice_preserves_sources():
558558
20,
559559
text="second",
560560
source=Source.DETECTRON2_ONNX,
561-
text_source=TextSource.EXTRACTED,
561+
is_extracted=True,
562562
),
563563
]
564564
text_regions = TextRegions.from_list(regions)
@@ -587,8 +587,8 @@ def test_textregions_from_coords_accepts_source():
587587
"""Test that TextRegion.from_coords() accepts source parameter"""
588588
# This should fail because from_coords() doesn't accept source parameter
589589
region = TextRegion.from_coords(
590-
0, 0, 10, 10, text="test", source=Source.YOLOX, text_source=TextSource.OCR
590+
0, 0, 10, 10, text="test", source=Source.YOLOX, is_extracted=True
591591
)
592592

593593
assert region.source == Source.YOLOX
594-
assert region.text_source == TextSource.OCR
594+
assert region.is_extracted

0 commit comments

Comments
 (0)