1111 PathInput ,
1212)
1313from mindee .input .page_options import KEEP_ONLY , REMOVE , PageOptions
14- from tests .utils import FILE_TYPES_DIR , V1_PRODUCT_DATA_DIR
14+ from tests .utils import FILE_TYPES_PATH , V1_PRODUCT_PATH
1515
1616pdfium = pytest .importorskip ("pypdfium2" )
1717
@@ -22,7 +22,9 @@ def _assert_page_options(input_source: LocalInputSource, numb_pages: int):
2222 # I.e., each page is read and rendered as a rasterized image.
2323 # These images are then compared as raw byte sequences.
2424 cut_pdf = pdfium .PdfDocument (input_source .file_object )
25- pdf = pdfium .PdfDocument (FILE_TYPES_DIR / "pdf" / f"multipage_cut-{ numb_pages } .pdf" )
25+ pdf = pdfium .PdfDocument (
26+ FILE_TYPES_PATH / "pdf" / f"multipage_cut-{ numb_pages } .pdf"
27+ )
2628 for idx in range (len (pdf )):
2729 pdf_page = pdf .get_page (idx )
2830 pdf_page_render = pdfium .PdfPage .render (pdf_page )
@@ -35,14 +37,14 @@ def _assert_page_options(input_source: LocalInputSource, numb_pages: int):
3537
3638
3739def test_pdf_reconstruct_ok ():
38- input_source = PathInput (FILE_TYPES_DIR / "pdf" / "multipage.pdf" )
40+ input_source = PathInput (FILE_TYPES_PATH / "pdf" / "multipage.pdf" )
3941 input_source .process_pdf (behavior = KEEP_ONLY , on_min_pages = 2 , page_indexes = range (5 ))
4042 assert isinstance (input_source .file_object , io .BytesIO )
4143
4244
4345@pytest .mark .parametrize ("numb_pages" , [1 , 2 , 3 ])
4446def test_process_pdf_cut_n_pages (numb_pages : int ):
45- input_source = PathInput (FILE_TYPES_DIR / "pdf" / "multipage.pdf" )
47+ input_source = PathInput (FILE_TYPES_PATH / "pdf" / "multipage.pdf" )
4648 assert input_source .page_count == 12
4749 input_source .process_pdf (
4850 behavior = KEEP_ONLY , on_min_pages = 2 , page_indexes = [0 , - 2 , - 1 ][:numb_pages ]
@@ -53,7 +55,7 @@ def test_process_pdf_cut_n_pages(numb_pages: int):
5355
5456@pytest .mark .parametrize ("numb_pages" , [1 , 2 , 3 ])
5557def test_apply_pages_pdf_cut_n_pages (numb_pages : int ):
56- input_source = PathInput (FILE_TYPES_DIR / "pdf" / "multipage.pdf" )
58+ input_source = PathInput (FILE_TYPES_PATH / "pdf" / "multipage.pdf" )
5759 assert input_source .page_count == 12
5860 input_source .apply_page_options (
5961 PageOptions (on_min_pages = 2 , page_indexes = [0 , - 2 , - 1 ][:numb_pages ])
@@ -63,7 +65,7 @@ def test_apply_pages_pdf_cut_n_pages(numb_pages: int):
6365
6466
6567def test_pdf_keep_5_first_pages ():
66- input_source = PathInput (FILE_TYPES_DIR / "pdf" / "multipage.pdf" )
68+ input_source = PathInput (FILE_TYPES_PATH / "pdf" / "multipage.pdf" )
6769 assert input_source .page_count == 12
6870 input_source .process_pdf (
6971 behavior = KEEP_ONLY , on_min_pages = 2 , page_indexes = [0 , 1 , 2 , 3 , 4 ]
@@ -72,7 +74,7 @@ def test_pdf_keep_5_first_pages():
7274
7375
7476def test_pdf_keep_invalid_pages ():
75- input_source = PathInput (FILE_TYPES_DIR / "pdf" / "multipage.pdf" )
77+ input_source = PathInput (FILE_TYPES_PATH / "pdf" / "multipage.pdf" )
7678 assert input_source .page_count == 12
7779 input_source .process_pdf (
7880 behavior = KEEP_ONLY , on_min_pages = 2 , page_indexes = [0 , 1 , 17 ]
@@ -81,7 +83,7 @@ def test_pdf_keep_invalid_pages():
8183
8284
8385def test_pdf_remove_5_last_pages ():
84- input_source = PathInput (FILE_TYPES_DIR / "pdf" / "multipage.pdf" )
86+ input_source = PathInput (FILE_TYPES_PATH / "pdf" / "multipage.pdf" )
8587 assert input_source .is_pdf () is True
8688 input_source .process_pdf (
8789 behavior = REMOVE , on_min_pages = 2 , page_indexes = [- 5 , - 4 , - 3 , - 2 , - 1 ]
@@ -90,7 +92,7 @@ def test_pdf_remove_5_last_pages():
9092
9193
9294def test_pdf_remove_5_first_pages ():
93- input_source = PathInput (FILE_TYPES_DIR / "pdf" / "multipage.pdf" )
95+ input_source = PathInput (FILE_TYPES_PATH / "pdf" / "multipage.pdf" )
9496 assert input_source .is_pdf () is True
9597 input_source .process_pdf (
9698 behavior = REMOVE , on_min_pages = 2 , page_indexes = list (range (5 ))
@@ -99,14 +101,14 @@ def test_pdf_remove_5_first_pages():
99101
100102
101103def test_pdf_remove_invalid_pages ():
102- input_source = PathInput (FILE_TYPES_DIR / "pdf" / "multipage.pdf" )
104+ input_source = PathInput (FILE_TYPES_PATH / "pdf" / "multipage.pdf" )
103105 assert input_source .is_pdf () is True
104106 input_source .process_pdf (behavior = REMOVE , on_min_pages = 2 , page_indexes = [16 ])
105107 assert input_source .page_count == 12
106108
107109
108110def test_pdf_keep_no_pages ():
109- input_source = PathInput (FILE_TYPES_DIR / "pdf" / "multipage.pdf" )
111+ input_source = PathInput (FILE_TYPES_PATH / "pdf" / "multipage.pdf" )
110112 assert input_source .is_pdf () is True
111113 # empty page indexes
112114 with pytest .raises (RuntimeError ):
@@ -119,7 +121,7 @@ def test_pdf_keep_no_pages():
119121
120122
121123def test_pdf_remove_all_pages ():
122- input_source = PathInput (FILE_TYPES_DIR / "pdf" / "multipage.pdf" )
124+ input_source = PathInput (FILE_TYPES_PATH / "pdf" / "multipage.pdf" )
123125 assert input_source .is_pdf () is True
124126 with pytest .raises (RuntimeError ):
125127 input_source .process_pdf (
@@ -128,37 +130,37 @@ def test_pdf_remove_all_pages():
128130
129131
130132def test_pdf_input_from_file ():
131- with open (FILE_TYPES_DIR / "pdf" / "multipage.pdf" , "rb" ) as fp :
133+ with open (FILE_TYPES_PATH / "pdf" / "multipage.pdf" , "rb" ) as fp :
132134 input_source = FileInput (fp )
133135 assert input_source .is_pdf () is True
134136 input_source .process_pdf (behavior = KEEP_ONLY , on_min_pages = 2 , page_indexes = [0 ])
135137 assert input_source .page_count == 1
136138
137139
138140def test_pdf_input_from_base64 ():
139- with open (V1_PRODUCT_DATA_DIR / "invoices" / "invoice_10p.txt" ) as fp :
141+ with open (V1_PRODUCT_PATH / "invoices" / "invoice_10p.txt" ) as fp :
140142 input_source = Base64Input (fp .read (), filename = "invoice_10p.pdf" )
141143 assert input_source .is_pdf () is True
142144 input_source .process_pdf (behavior = KEEP_ONLY , on_min_pages = 2 , page_indexes = [0 ])
143145 assert input_source .page_count == 1
144146
145147
146148def test_pdf_input_from_bytes ():
147- with open (V1_PRODUCT_DATA_DIR / "invoices" / "invoice_10p.pdf" , "rb" ) as fp :
149+ with open (V1_PRODUCT_PATH / "invoices" / "invoice_10p.pdf" , "rb" ) as fp :
148150 input_source = BytesInput (fp .read (), filename = "invoice_10p.pdf" )
149151 assert input_source .is_pdf () is True
150152 input_source .process_pdf (behavior = KEEP_ONLY , on_min_pages = 2 , page_indexes = [0 ])
151153 assert input_source .page_count == 1
152154
153155
154156def test_pdf_blank_check ():
155- input_source = PathInput (FILE_TYPES_DIR / "pdf" / "blank.pdf" )
157+ input_source = PathInput (FILE_TYPES_PATH / "pdf" / "blank.pdf" )
156158 with pytest .raises (MindeeError ):
157159 input_source .process_pdf (behavior = KEEP_ONLY , on_min_pages = 2 , page_indexes = [0 ])
158160
159- input_source = PathInput (FILE_TYPES_DIR / "pdf" / "blank_1.pdf" )
161+ input_source = PathInput (FILE_TYPES_PATH / "pdf" / "blank_1.pdf" )
160162 with pytest .raises (MindeeError ):
161163 input_source .process_pdf (behavior = KEEP_ONLY , on_min_pages = 2 , page_indexes = [0 ])
162164
163- input_not_blank = PathInput (FILE_TYPES_DIR / "pdf" / "not_blank_image_only.pdf" )
165+ input_not_blank = PathInput (FILE_TYPES_PATH / "pdf" / "not_blank_image_only.pdf" )
164166 assert input_not_blank .page_count == 1
0 commit comments