-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_split_operation.py
More file actions
55 lines (39 loc) · 1.54 KB
/
test_split_operation.py
File metadata and controls
55 lines (39 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import json
import pytest
from mindee.input.sources.path_input import PathInput
from mindee.v2.product.split.split_response import (
SplitResponse,
)
from tests.utils import V2_PRODUCT_DATA_DIR
@pytest.fixture
def splits_default():
return (
V2_PRODUCT_DATA_DIR / "extraction" / "financial_document" / "default_sample.jpg"
)
@pytest.fixture
def splits_5p():
return V2_PRODUCT_DATA_DIR / "split" / "invoice_5p.pdf"
@pytest.fixture
def splits_single_page_json_path():
return V2_PRODUCT_DATA_DIR / "split" / "split_single.json"
@pytest.fixture
def splits_multi_page_json_path():
return V2_PRODUCT_DATA_DIR / "split" / "split_multiple.json"
def test_single_page_split_split(splits_default, splits_single_page_json_path):
input_sample = PathInput(splits_default)
with open(splits_single_page_json_path, "rb") as f:
response = json.load(f)
doc = SplitResponse(response)
extracted_splits = doc.extract_from_file(input_sample)
assert len(extracted_splits) == 1
assert extracted_splits[0].get_page_count() == 1
def test_multi_page_receipt_split(splits_5p, splits_multi_page_json_path):
input_sample = PathInput(splits_5p)
with open(splits_multi_page_json_path, "rb") as f:
response = json.load(f)
doc = SplitResponse(response)
extracted_splits = doc.extract_from_file(input_sample)
assert len(extracted_splits) == 3
assert extracted_splits[0].get_page_count() == 1
assert extracted_splits[1].get_page_count() == 3
assert extracted_splits[2].get_page_count() == 1