Skip to content

Commit 26ca48e

Browse files
re-organize tests
1 parent 8c43b0f commit 26ca48e

File tree

66 files changed

+267
-218
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+267
-218
lines changed

tests/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
REQUEST_TIMEOUT_ENV_NAME,
88
)
99

10-
DATA_DIR = Path("./tests/data/")
11-
12-
EXTRAS_DIR = DATA_DIR / "extras"
13-
FILE_TYPES_DIR = DATA_DIR / "file_types"
14-
V2_DATA_DIR = DATA_DIR / "v2"
15-
PRODUCT_DATA_DIR = DATA_DIR / "products"
10+
ROOT_DATA_DIR = Path("./tests/data/")
11+
V1_DATA_DIR = ROOT_DATA_DIR / "v1"
12+
V2_DATA_DIR = ROOT_DATA_DIR / "v2"
13+
EXTRAS_DIR = V1_DATA_DIR / "extras"
14+
FILE_TYPES_DIR = ROOT_DATA_DIR / "file_types"
15+
V1_PRODUCT_DATA_DIR = V1_DATA_DIR / "products"
1616

1717

1818
def clear_envvars(monkeypatch) -> None:

tests/v1/api/test_async_response.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
from mindee.parsing.common.api_request import RequestStatus
1111
from mindee.parsing.common.async_predict_response import AsyncPredictResponse
1212
from mindee.product.invoice_splitter.invoice_splitter_v1 import InvoiceSplitterV1
13+
from tests.utils import V1_DATA_DIR, V1_PRODUCT_DATA_DIR
1314

14-
ASYNC_DIR = Path("./tests/data/async")
15+
ASYNC_DIR = V1_DATA_DIR / "async"
1516

1617
FILE_PATH_POST_SUCCESS = ASYNC_DIR / "post_success.json"
1718
FILE_PATH_POST_FAIL = ASYNC_DIR / "post_fail_forbidden.json"
@@ -41,7 +42,9 @@ def content(self) -> str:
4142

4243
@pytest.fixture
4344
def dummy_file_input() -> PathInput:
44-
file_input = PathInput("./tests/data/products/invoice_splitter/default_sample.pdf")
45+
file_input = PathInput(
46+
V1_PRODUCT_DATA_DIR / "invoice_splitter" / "default_sample.pdf"
47+
)
4548
return file_input
4649

4750

tests/v1/api/test_feedback_response.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import json
22

33
from mindee.parsing.common.feedback_response import FeedbackResponse
4+
from tests.utils import V1_PRODUCT_DATA_DIR
45

56

67
def test_empty_feedback_response():
78
response = json.load(
8-
open("./tests/data/products/invoices/feedback_response/empty.json")
9+
open(V1_PRODUCT_DATA_DIR / "invoices" / "feedback_response" / "empty.json")
910
)
1011
feedback_response = FeedbackResponse(response)
1112
assert feedback_response is not None

tests/v1/api/test_response.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
from mindee.product.passport.passport_v1_document import PassportV1Document
1515
from mindee.product.receipt.receipt_v5 import ReceiptV5
1616
from mindee.product.receipt.receipt_v5_document import ReceiptV5Document
17+
from tests.utils import V1_PRODUCT_DATA_DIR
1718

1819

1920
def test_invoice_receipt_v5():
2021
response = json.load(
21-
open("./tests/data/products/invoices/response_v4/complete.json")
22+
open(V1_PRODUCT_DATA_DIR / "invoices" / "response_v4" / "complete.json")
2223
)
2324
parsed_response = PredictResponse(InvoiceV4, response)
2425
assert isinstance(parsed_response.document.inference, InvoiceV4)
@@ -29,7 +30,7 @@ def test_invoice_receipt_v5():
2930

3031
def test_response_receipt_v5():
3132
response = json.load(
32-
open("./tests/data/products/expense_receipts/response_v5/complete.json")
33+
open(V1_PRODUCT_DATA_DIR / "expense_receipts" / "response_v5" / "complete.json")
3334
)
3435
parsed_response = PredictResponse(ReceiptV5, response)
3536
assert isinstance(parsed_response.document.inference, ReceiptV5)
@@ -41,7 +42,10 @@ def test_response_receipt_v5():
4142
def test_response_financial_doc_with_receipt():
4243
response = json.load(
4344
open(
44-
"./tests/data/products/financial_document/response_v1/complete_receipt.json"
45+
V1_PRODUCT_DATA_DIR
46+
/ "financial_document"
47+
/ "response_v1"
48+
/ "complete_receipt.json"
4549
)
4650
)
4751
parsed_response = PredictResponse(FinancialDocumentV1, response)
@@ -55,7 +59,7 @@ def test_response_financial_doc_with_receipt():
5559

5660
def test_response_passport_v1():
5761
response = json.load(
58-
open("./tests/data/products/passport/response_v1/complete.json")
62+
open(V1_PRODUCT_DATA_DIR / "passport" / "response_v1" / "complete.json")
5963
)
6064
parsed_response = PredictResponse(PassportV1, response)
6165
assert isinstance(parsed_response.document.inference, PassportV1)
@@ -67,7 +71,7 @@ def test_response_passport_v1():
6771

6872
def test_response_fr_idcard_v2():
6973
response = json.load(
70-
open("./tests/data/products/idcard_fr/response_v2/complete.json")
74+
open(V1_PRODUCT_DATA_DIR / "idcard_fr" / "response_v2" / "complete.json")
7175
)
7276
parsed_response = PredictResponse(IdCardV2, response)
7377
assert isinstance(parsed_response.document.inference, IdCardV2)

tests/v1/extraction/test_image_extractor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
from mindee.extraction.common.image_extractor import extract_multiple_images_from_source
77
from mindee.input.sources.path_input import PathInput
88
from mindee.product.barcode_reader.barcode_reader_v1 import BarcodeReaderV1
9-
from tests.utils import PRODUCT_DATA_DIR
9+
from tests.utils import V1_PRODUCT_DATA_DIR
1010

1111

1212
@pytest.fixture
1313
def barcode_path():
14-
return PRODUCT_DATA_DIR / "barcode_reader" / "default_sample.jpg"
14+
return V1_PRODUCT_DATA_DIR / "barcode_reader" / "default_sample.jpg"
1515

1616

1717
@pytest.fixture
1818
def barcode_json_path():
19-
return PRODUCT_DATA_DIR / "barcode_reader" / "response_v1" / "complete.json"
19+
return V1_PRODUCT_DATA_DIR / "barcode_reader" / "response_v1" / "complete.json"
2020

2121

2222
def test_barcode_image_extraction(barcode_path, barcode_json_path):

tests/v1/extraction/test_invoice_splitter_auto_extraction.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
from mindee.parsing.common.document import Document
99
from mindee.product.invoice.invoice_v4 import InvoiceV4
1010
from mindee.product.invoice_splitter.invoice_splitter_v1 import InvoiceSplitterV1
11-
from tests.utils import PRODUCT_DATA_DIR, levenshtein_ratio
11+
from tests.utils import V1_PRODUCT_DATA_DIR, levenshtein_ratio
1212
from tests.v1.product import get_id, get_version
1313

1414

1515
@pytest.fixture
1616
def invoice_splitter_5p_path():
17-
return PRODUCT_DATA_DIR / "invoice_splitter" / "invoice_5p.pdf"
17+
return V1_PRODUCT_DATA_DIR / "invoice_splitter" / "invoice_5p.pdf"
1818

1919

2020
def prepare_invoice_return(rst_file_path: Path, invoice_prediction: Document):
@@ -31,7 +31,7 @@ def prepare_invoice_return(rst_file_path: Path, invoice_prediction: Document):
3131
def test_pdf_should_extract_invoices_strict():
3232
client = Client()
3333
invoice_splitter_input = PathInput(
34-
PRODUCT_DATA_DIR / "invoice_splitter" / "default_sample.pdf"
34+
V1_PRODUCT_DATA_DIR / "invoice_splitter" / "default_sample.pdf"
3535
)
3636
response = client.enqueue_and_parse(
3737
InvoiceSplitterV1, invoice_splitter_input, close_file=False
@@ -50,7 +50,10 @@ def test_pdf_should_extract_invoices_strict():
5050

5151
invoice_0 = client.parse(InvoiceV4, extracted_pdfs_strict[0].as_input_source())
5252
test_string_rst_invoice_0 = prepare_invoice_return(
53-
PRODUCT_DATA_DIR / "invoices" / "response_v4" / "summary_full_invoice_p1.rst",
53+
V1_PRODUCT_DATA_DIR
54+
/ "invoices"
55+
/ "response_v4"
56+
/ "summary_full_invoice_p1.rst",
5457
invoice_0.document,
5558
)
5659
assert levenshtein_ratio(test_string_rst_invoice_0, str(invoice_0.document)) >= 0.97

tests/v1/extraction/test_multi_receipts_extractor.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,33 @@
1010
from mindee.product.multi_receipts_detector.multi_receipts_detector_v1 import (
1111
MultiReceiptsDetectorV1,
1212
)
13-
from tests.utils import PRODUCT_DATA_DIR
13+
from tests.utils import V1_PRODUCT_DATA_DIR
1414

1515

1616
@pytest.fixture
1717
def multi_receipts_single_page_path():
18-
return PRODUCT_DATA_DIR / "multi_receipts_detector" / "default_sample.jpg"
18+
return V1_PRODUCT_DATA_DIR / "multi_receipts_detector" / "default_sample.jpg"
1919

2020

2121
@pytest.fixture
2222
def multi_receipts_single_page_json_path():
2323
return (
24-
PRODUCT_DATA_DIR / "multi_receipts_detector" / "response_v1" / "complete.json"
24+
V1_PRODUCT_DATA_DIR
25+
/ "multi_receipts_detector"
26+
/ "response_v1"
27+
/ "complete.json"
2528
)
2629

2730

2831
@pytest.fixture
2932
def multi_receipts_multi_page_path():
30-
return PRODUCT_DATA_DIR / "multi_receipts_detector" / "multipage_sample.pdf"
33+
return V1_PRODUCT_DATA_DIR / "multi_receipts_detector" / "multipage_sample.pdf"
3134

3235

3336
@pytest.fixture
3437
def multi_receipts_multi_page_json_path():
3538
return (
36-
PRODUCT_DATA_DIR
39+
V1_PRODUCT_DATA_DIR
3740
/ "multi_receipts_detector"
3841
/ "response_v1"
3942
/ "multipage_sample.json"

tests/v1/extraction/test_pdf_extractor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@
88
from mindee.product.invoice_splitter.invoice_splitter_v1_document import (
99
InvoiceSplitterV1Document,
1010
)
11-
from tests.utils import PRODUCT_DATA_DIR
11+
from tests.utils import V1_PRODUCT_DATA_DIR
1212

1313

1414
@pytest.fixture
1515
def invoice_default_sample_path():
16-
return PRODUCT_DATA_DIR / "invoices" / "default_sample.jpg"
16+
return V1_PRODUCT_DATA_DIR / "invoices" / "default_sample.jpg"
1717

1818

1919
@pytest.fixture
2020
def invoice_splitter_5p_path():
21-
return PRODUCT_DATA_DIR / "invoice_splitter" / "invoice_5p.pdf"
21+
return V1_PRODUCT_DATA_DIR / "invoice_splitter" / "invoice_5p.pdf"
2222

2323

2424
@pytest.fixture
2525
def loaded_prediction():
2626
dummy_client = Client("dummy_key")
2727
loaded_prediction_path = (
28-
PRODUCT_DATA_DIR / "invoice_splitter" / "response_v1" / "complete.json"
28+
V1_PRODUCT_DATA_DIR / "invoice_splitter" / "response_v1" / "complete.json"
2929
)
3030
input_response = LocalResponse(loaded_prediction_path)
3131
response = dummy_client.load_prediction(InvoiceSplitterV1, input_response)

tests/v1/extras/test_extras_integration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from mindee import Client
44
from mindee.product.international_id.international_id_v2 import InternationalIdV2
55
from mindee.product.invoice.invoice_v4 import InvoiceV4
6-
from tests.utils import PRODUCT_DATA_DIR
6+
from tests.utils import V1_PRODUCT_DATA_DIR
77

88

99
@pytest.fixture
@@ -15,7 +15,7 @@ def client():
1515
@pytest.mark.integration
1616
def test_send_cropper_extra(client):
1717
sample = client.source_from_path(
18-
PRODUCT_DATA_DIR / "invoices" / "default_sample.jpg",
18+
V1_PRODUCT_DATA_DIR / "invoices" / "default_sample.jpg",
1919
)
2020
response = client.parse(InvoiceV4, sample, cropper=True)
2121
assert response.document.inference.pages[0].extras.cropper
@@ -24,7 +24,7 @@ def test_send_cropper_extra(client):
2424
@pytest.mark.integration
2525
def test_send_full_text_ocr_extra(client):
2626
sample = client.source_from_path(
27-
PRODUCT_DATA_DIR / "international_id" / "default_sample.jpg",
27+
V1_PRODUCT_DATA_DIR / "international_id" / "default_sample.jpg",
2828
)
2929
response = client.enqueue_and_parse(InternationalIdV2, sample, full_text=True)
3030
assert response.document.extras.full_text_ocr

tests/v1/input/test_apply_page_options.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
LocalInputSource,
1313
PathInput,
1414
)
15-
from tests.utils import FILE_TYPES_DIR, PRODUCT_DATA_DIR
15+
from tests.utils import FILE_TYPES_DIR, V1_PRODUCT_DATA_DIR
1616

1717

1818
def _assert_page_options(input_source: LocalInputSource, numb_pages: int):
@@ -135,15 +135,15 @@ def test_pdf_input_from_file():
135135

136136

137137
def test_pdf_input_from_base64():
138-
with open(PRODUCT_DATA_DIR / "invoices" / "invoice_10p.txt", "rt") as fp:
138+
with open(V1_PRODUCT_DATA_DIR / "invoices" / "invoice_10p.txt", "rt") as fp:
139139
input_source = Base64Input(fp.read(), filename="invoice_10p.pdf")
140140
assert input_source.is_pdf() is True
141141
input_source.process_pdf(behavior=KEEP_ONLY, on_min_pages=2, page_indexes=[0])
142142
assert input_source.page_count == 1
143143

144144

145145
def test_pdf_input_from_bytes():
146-
with open(PRODUCT_DATA_DIR / "invoices" / "invoice_10p.pdf", "rb") as fp:
146+
with open(V1_PRODUCT_DATA_DIR / "invoices" / "invoice_10p.pdf", "rb") as fp:
147147
input_source = BytesInput(fp.read(), filename="invoice_10p.pdf")
148148
assert input_source.is_pdf() is True
149149
input_source.process_pdf(behavior=KEEP_ONLY, on_min_pages=2, page_indexes=[0])

0 commit comments

Comments
 (0)