1+ import re
12from pathlib import Path
23
34import pytest
45
56from mindee .input .path_input import PathInput
7+ from mindee .pdf .extracted_pdf import ExtractedPDF
68from mindee .v1 .client import Client
79from mindee .v1 .parsing .common import Document
810from mindee .v1 .pdf .pdf_extractor import PDFExtractor
@@ -27,6 +29,16 @@ def prepare_invoice_return(rst_file_path: Path, invoice_prediction: Document):
2729 return rst_content
2830
2931
32+ _VOLATILE = re .compile (
33+ rb"/ID\s*\[<[0-9A-Fa-f]*>\s*<[0-9A-Fa-f]*>\]|/CreationDate\s*\([^)]*\)|/ModDate\s*\([^)]*\)"
34+ )
35+
36+
37+ def _pdf_fingerprint (pdf : ExtractedPDF ) -> bytes :
38+ pdf .buffer .seek (0 )
39+ return _VOLATILE .sub (b"" , pdf .buffer .read ())
40+
41+
3042@pytest .mark .bernard_ledit
3143@pytest .mark .integration
3244def test_pdf_should_extract_invoices_strict ():
@@ -51,8 +63,10 @@ def test_pdf_should_extract_invoices_strict():
5163 [int_list .page_indexes for int_list in inference .prediction .invoice_page_groups ]
5264 )
5365 for i , extracted_pdf in enumerate (extracted_base_pdfs ):
54- assert extracted_pdf .filename == extracted_pdfs_strict [i ].filename
55- assert extracted_pdf .buffer .read () == extracted_pdfs_strict [i ].buffer .read ()
66+ strict = extracted_pdfs_strict [i ]
67+ assert extracted_pdf .filename == strict .filename
68+ assert extracted_pdf .page_indexes == strict .page_indexes
69+ assert _pdf_fingerprint (extracted_pdf ) == _pdf_fingerprint (strict )
5670
5771 assert len (extracted_pdfs_not_strict ) == 2
5872 assert extracted_pdfs_not_strict [0 ].filename == "default_sample_pages-001-001.pdf"
0 commit comments