Skip to content

Commit 5b19c0b

Browse files
committed
📝 update proof of address docstrings
1 parent 3f2dd65 commit 5b19c0b

File tree

2 files changed

+85
-94
lines changed

2 files changed

+85
-94
lines changed

mindee/documents/proof_of_address/proof_of_address_v1.py

Lines changed: 64 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,26 @@
88

99

1010
class ProofOfAddressV1(Document):
11+
"""Proof of Address v1 prediction results."""
12+
1113
locale: LocaleField
12-
"""locale information"""
13-
date: DateField
14-
"""ISO date yyyy-mm-dd. Works both for European and US dates."""
15-
dates: List[DateField] = []
16-
"""All extracted ISO date yyyy-mm-dd"""
17-
issuer_address: TextField
18-
"""Address of the document's issuer."""
19-
issuer_company_registration: List[CompanyRegistrationField] = []
20-
"""Generic: VAT NUMBER, TAX ID, COMPANY REGISTRATION NUMBER or country specific."""
14+
"""The locale detected on the document."""
2115
issuer_name: TextField
22-
"""Name of the person or company issuing the document."""
23-
recipient_address: TextField
24-
"""Address of the recipient."""
25-
recipient_company_registration: List[CompanyRegistrationField] = []
26-
"""Generic: VAT NUMBER, TAX ID, COMPANY REGISTRATION NUMBER or country specific."""
16+
"""The name of the person or company issuing the document."""
17+
issuer_company_registration: List[CompanyRegistrationField]
18+
"""List of company registrations found for the issuer."""
19+
issuer_address: TextField
20+
"""The address of the document's issuer."""
2721
recipient_name: TextField
28-
"""Name of the document's recipient."""
22+
"""The name of the person or company receiving the document."""
23+
recipient_company_registration: List[CompanyRegistrationField]
24+
"""List of company registrations found for the recipient."""
25+
recipient_address: TextField
26+
"""The address of the recipient."""
27+
dates: List[DateField]
28+
"""List of dates found on the document."""
29+
date: DateField
30+
"""The date the document was issued."""
2931

3032
def __init__(
3133
self,
@@ -34,7 +36,7 @@ def __init__(
3436
page_n: Optional[int] = None,
3537
):
3638
"""
37-
Proof of Address document.
39+
Proof of Address v1 prediction results.
3840
3941
:param api_prediction: Raw prediction from HTTP response
4042
:param input_source: Input object
@@ -55,56 +57,69 @@ def _build_from_api_prediction(
5557
Build the object from the prediction API JSON.
5658
5759
:param api_prediction: Raw prediction from HTTP response
58-
:param page_n: Page number for multi pages pdf input
60+
:param page_n: Page number
5961
"""
6062
self.locale = LocaleField(
61-
api_prediction["locale"], value_key="language", page_n=page_n
63+
api_prediction["locale"],
64+
page_n=page_n,
65+
)
66+
self.issuer_name = TextField(
67+
api_prediction["issuer_name"],
68+
page_n=page_n,
6269
)
63-
self.date = DateField(api_prediction["date"], page_n=page_n)
64-
self.dates = [
65-
DateField(tax_prediction, page_n=page_n)
66-
for tax_prediction in api_prediction["dates"]
67-
]
68-
self.issuer_name = TextField(api_prediction["issuer_name"], page_n=page_n)
69-
self.issuer_address = TextField(api_prediction["issuer_address"], page_n=page_n)
7070
self.issuer_company_registration = [
71-
CompanyRegistrationField(tax_prediction, page_n=page_n)
72-
for tax_prediction in api_prediction["issuer_company_registration"]
71+
CompanyRegistrationField(prediction, page_n=page_n)
72+
for prediction in api_prediction["issuer_company_registration"]
7373
]
74-
self.recipient_name = TextField(api_prediction["recipient_name"], page_n=page_n)
75-
self.recipient_address = TextField(
76-
api_prediction["recipient_address"], page_n=page_n
74+
self.issuer_address = TextField(
75+
api_prediction["issuer_address"],
76+
page_n=page_n,
77+
)
78+
self.recipient_name = TextField(
79+
api_prediction["recipient_name"],
80+
page_n=page_n,
7781
)
7882
self.recipient_company_registration = [
79-
CompanyRegistrationField(tax_prediction, page_n=page_n)
80-
for tax_prediction in api_prediction["recipient_company_registration"]
83+
CompanyRegistrationField(prediction, page_n=page_n)
84+
for prediction in api_prediction["recipient_company_registration"]
8185
]
86+
self.recipient_address = TextField(
87+
api_prediction["recipient_address"],
88+
page_n=page_n,
89+
)
90+
self.dates = [
91+
DateField(prediction, page_n=page_n)
92+
for prediction in api_prediction["dates"]
93+
]
94+
self.date = DateField(
95+
api_prediction["date"],
96+
page_n=page_n,
97+
)
8298

8399
def __str__(self) -> str:
84-
issuer_company_registrations = "; ".join(
85-
[str(n.value) for n in self.issuer_company_registration]
100+
issuer_company_registration = f"\n { ' ' * 28 }".join(
101+
[str(item) for item in self.issuer_company_registration],
102+
)
103+
recipient_company_registration = f"\n { ' ' * 31 }".join(
104+
[str(item) for item in self.recipient_company_registration],
86105
)
87-
recipient_company_registrations = "; ".join(
88-
[str(n.value) for n in self.recipient_company_registration]
106+
dates = f"\n { ' ' * 6 }".join(
107+
[str(item) for item in self.dates],
89108
)
90-
dates = "\n ".join([str(n.value) for n in self.dates])
91109
return clean_out_string(
92110
"----- Proof of Address V1 -----\n"
93111
f"Filename: {self.filename or ''}\n"
94-
f"Locale: {self.locale}\n"
95-
f"Issuer name: {self.issuer_name}\n"
96-
f"Issuer Address: {self.issuer_address}\n"
97-
f"Issuer Company Registrations: {issuer_company_registrations}\n"
98-
f"Recipient name: {self.recipient_name}\n"
99-
f"Recipient Address: {self.recipient_address}\n"
100-
f"Recipient Company Registrations: {recipient_company_registrations}\n"
101-
f"Issuance Date: {self.date}\n"
102-
f"Dates: {dates}\n"
112+
f"Locale: { self.locale }\n"
113+
f"Issuer Name: { self.issuer_name }\n"
114+
f"Issuer Company Registrations: { issuer_company_registration }\n"
115+
f"Issuer Address: { self.issuer_address }\n"
116+
f"Recipient Name: { self.recipient_name }\n"
117+
f"Recipient Company Registrations: { recipient_company_registration }\n"
118+
f"Recipient Address: { self.recipient_address }\n"
119+
f"Dates: { dates }\n"
120+
f"Date of Issue: { self.date }\n"
103121
"----------------------"
104122
)
105123

106-
def _checklist(self) -> None:
107-
pass
108-
109124

110125
TypeProofOfAddressV1 = TypeVar("TypeProofOfAddressV1", bound=ProofOfAddressV1)

tests/documents/test_proof_of_address_v1.py

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,66 +3,42 @@
33
import pytest
44

55
from mindee.documents.proof_of_address.proof_of_address_v1 import ProofOfAddressV1
6-
from tests import PROOF_OF_ADDRESS_DATA_DIR
6+
7+
PROOF_OF_ADDRESS_DATA_DIR = "./tests/data/proof_of_address"
78

89
FILE_PATH_PROOF_OF_ADDRESS_V1_COMPLETE = (
9-
f"{PROOF_OF_ADDRESS_DATA_DIR}/response_v1/complete.json"
10+
f"{ PROOF_OF_ADDRESS_DATA_DIR }/response_v1/complete.json"
11+
)
12+
FILE_PATH_PROOF_OF_ADDRESS_V1_EMPTY = (
13+
f"{ PROOF_OF_ADDRESS_DATA_DIR }/response_v1/empty.json"
1014
)
1115

1216

1317
@pytest.fixture
14-
def proof_of_address_v1_doc_object() -> ProofOfAddressV1:
18+
def proof_of_address_v1_doc() -> ProofOfAddressV1:
1519
json_data = json.load(open(FILE_PATH_PROOF_OF_ADDRESS_V1_COMPLETE))
16-
return ProofOfAddressV1(
17-
api_prediction=json_data["document"]["inference"], page_n=None
18-
)
20+
return ProofOfAddressV1(json_data["document"]["inference"], page_n=None)
1921

2022

2123
@pytest.fixture
22-
def proof_of_address_v1_doc_object_empty() -> ProofOfAddressV1:
23-
json_data = json.load(open(f"{PROOF_OF_ADDRESS_DATA_DIR}/response_v1/empty.json"))
24-
return ProofOfAddressV1(
25-
api_prediction=json_data["document"]["inference"], page_n=None
26-
)
24+
def proof_of_address_v1_doc_empty() -> ProofOfAddressV1:
25+
json_data = json.load(open(FILE_PATH_PROOF_OF_ADDRESS_V1_EMPTY))
26+
return ProofOfAddressV1(json_data["document"]["inference"], page_n=None)
2727

2828

2929
@pytest.fixture
30-
def proof_of_address_v1_page_object() -> ProofOfAddressV1:
30+
def proof_of_address_v1_page0():
3131
json_data = json.load(open(FILE_PATH_PROOF_OF_ADDRESS_V1_COMPLETE))
32-
return ProofOfAddressV1(
33-
api_prediction=json_data["document"]["inference"]["pages"][0], page_n=0
34-
)
35-
36-
37-
def test_doc_constructor(proof_of_address_v1_doc_object):
38-
doc_str = (
39-
open(f"{PROOF_OF_ADDRESS_DATA_DIR}/response_v1/doc_to_string.txt")
40-
.read()
41-
.strip()
42-
)
43-
assert proof_of_address_v1_doc_object.issuer_name.page_n == 0
44-
assert str(proof_of_address_v1_doc_object) == doc_str
32+
return ProofOfAddressV1(json_data["document"]["inference"]["pages"][0], page_n=0)
4533

4634

47-
def test_page_constructor(proof_of_address_v1_page_object):
48-
doc_str = (
49-
open(f"{PROOF_OF_ADDRESS_DATA_DIR}/response_v1/page0_to_string.txt")
50-
.read()
51-
.strip()
52-
)
53-
assert proof_of_address_v1_page_object.orientation.value == 0
54-
assert proof_of_address_v1_page_object.issuer_name.page_n == 0
55-
assert str(proof_of_address_v1_page_object) == doc_str
56-
assert len(proof_of_address_v1_page_object.cropper) == 0
35+
def test_doc_constructor(proof_of_address_v1_doc):
36+
file_path = f"{ PROOF_OF_ADDRESS_DATA_DIR }/response_v1/doc_to_string.txt"
37+
reference_str = open(file_path, "r", encoding="utf-8").read().strip()
38+
assert str(proof_of_address_v1_doc) == reference_str
5739

5840

59-
def test_all_na(proof_of_address_v1_doc_object_empty):
60-
assert proof_of_address_v1_doc_object_empty.locale.value is None
61-
assert proof_of_address_v1_doc_object_empty.date.value is None
62-
assert len(proof_of_address_v1_doc_object_empty.dates) == 0
63-
assert proof_of_address_v1_doc_object_empty.issuer_address.value is None
64-
assert len(proof_of_address_v1_doc_object_empty.issuer_company_registration) == 0
65-
assert proof_of_address_v1_doc_object_empty.issuer_name.value is None
66-
assert proof_of_address_v1_doc_object_empty.recipient_address.value is None
67-
assert len(proof_of_address_v1_doc_object_empty.recipient_company_registration) == 0
68-
assert proof_of_address_v1_doc_object_empty.recipient_name.value is None
41+
def test_page0_constructor(proof_of_address_v1_page0):
42+
file_path = f"{ PROOF_OF_ADDRESS_DATA_DIR }/response_v1/page0_to_string.txt"
43+
reference_str = open(file_path, "r", encoding="utf-8").read().strip()
44+
assert str(proof_of_address_v1_page0) == reference_str

0 commit comments

Comments
 (0)