forked from Belval/pdf2image
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
543 lines (473 loc) · 26.7 KB
/
tests.py
File metadata and controls
543 lines (473 loc) · 26.7 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
import os
import sys
import tempfile
import unittest
import time
import subprocess
# polyfill for python27
try:
from tempfile import TemporaryDirectory
except ImportError:
import shutil
class TemporaryDirectory(object):
def __init__(self):
self.name = tempfile.mkdtemp()
def __enter__(self):
return self.name
def __exit__(self, exc, value, tb):
shutil.rmtree(self.name)
from memory_profiler import profile as profile_memory
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from pdf2image import convert_from_bytes, convert_from_path
from functools import wraps
PROFILE_MEMORY = False
try:
subprocess.call(["pdfinfo", "-h"], stdout=open(os.devnull, 'w'), stderr=open(os.devnull, 'w'))
POPPLER_INSTALLED = True
except OSError as e:
if e.errno == os.errno.ENOENT:
POPPLER_INSTALLED = False
def profile(f):
if PROFILE_MEMORY:
@wraps(f)
@profile_memory
def wrapped(*args, **kwargs):
r = f(*args, **kwargs)
return r
return wrapped
else:
@wraps(f)
def wrapped(*args, **kwargs):
r = f(*args, **kwargs)
return r
return wrapped
class PDFConversionMethods(unittest.TestCase):
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_bytes(self):
start_time = time.time()
with open('./tests/test.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read())
self.assertTrue(len(images_from_bytes) == 1)
print('test_conversion_from_bytes: {} sec'.format(time.time() - start_time))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_path(self):
start_time = time.time()
images_from_path = convert_from_path('./tests/test.pdf')
self.assertTrue(len(images_from_path) == 1)
print('test_conversion_from_path: {} sec'.format(time.time() - start_time))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_bytes_using_dir(self):
start_time = time.time()
with TemporaryDirectory() as path:
with open('./tests/test.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read(), output_folder=path)
self.assertTrue(len(images_from_bytes) == 1)
[im.close() for im in images_from_bytes]
print('test_conversion_from_bytes_using_dir: {} sec'.format(time.time() - start_time))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_path_using_dir(self):
start_time = time.time()
with TemporaryDirectory() as path:
images_from_path = convert_from_path('./tests/test.pdf', output_folder=path)
self.assertTrue(len(images_from_path) == 1)
[im.close() for im in images_from_path]
print('test_conversion_from_path_using_dir: {} sec'.format(time.time() - start_time))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_bytes_14(self):
start_time = time.time()
with open('./tests/test_14.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read())
self.assertTrue(len(images_from_bytes) == 14)
print('test_conversion_from_bytes_14: {} sec'.format((time.time() - start_time) / 14.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_path_14(self):
start_time = time.time()
images_from_path = convert_from_path('./tests/test_14.pdf')
self.assertTrue(len(images_from_path) == 14)
print('test_conversion_from_path_14: {} sec'.format((time.time() - start_time) / 14.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_bytes_using_dir_14(self):
start_time = time.time()
with TemporaryDirectory() as path:
with open('./tests/test_14.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read(), output_folder=path)
self.assertTrue(len(images_from_bytes) == 14)
[im.close() for im in images_from_bytes]
print('test_conversion_from_bytes_using_dir_14: {} sec'.format((time.time() - start_time) / 14.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_path_using_dir_14(self):
start_time = time.time()
with TemporaryDirectory() as path:
images_from_path = convert_from_path('./tests/test_14.pdf', output_folder=path)
self.assertTrue(len(images_from_path) == 14)
[im.close() for im in images_from_path]
print('test_conversion_from_path_using_dir_14: {} sec'.format((time.time() - start_time) / 14.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
@unittest.skipIf("TRAVIS" in os.environ and os.environ["TRAVIS"] == "true", "Skipping this test on Travis CI.")
def test_conversion_from_bytes_241(self): # pragma: no cover
start_time = time.time()
with open('./tests/test_241.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read())
self.assertTrue(len(images_from_bytes) == 241)
print('test_conversion_from_bytes_241: {} sec'.format((time.time() - start_time) / 241.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
@unittest.skipIf("TRAVIS" in os.environ and os.environ["TRAVIS"] == "true", "Skipping this test on Travis CI.")
def test_conversion_from_path_241(self): # pragma: no cover
start_time = time.time()
images_from_path = convert_from_path('./tests/test_241.pdf')
self.assertTrue(len(images_from_path) == 241)
print('test_conversion_from_path_241: {} sec'.format((time.time() - start_time) / 241.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
@unittest.skipIf("TRAVIS" in os.environ and os.environ["TRAVIS"] == "true", "Skipping this test on Travis CI.")
def test_conversion_from_bytes_using_dir_241(self): # pragma: no cover
start_time = time.time()
with TemporaryDirectory() as path:
with open('./tests/test_241.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read(), output_folder=path)
self.assertTrue(len(images_from_bytes) == 241)
[im.close() for im in images_from_bytes]
print('test_conversion_from_bytes_using_dir_241: {} sec'.format((time.time() - start_time) / 241.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
@unittest.skipIf("TRAVIS" in os.environ and os.environ["TRAVIS"] == "true", "Skipping this test on Travis CI.")
def test_conversion_from_path_using_dir_241(self): # pragma: no cover
start_time = time.time()
with TemporaryDirectory() as path:
images_from_path = convert_from_path('./tests/test_241.pdf', output_folder=path)
self.assertTrue(len(images_from_path) == 241)
[im.close() for im in images_from_path]
print('test_conversion_from_path_using_dir_241: {} sec'.format((time.time() - start_time) / 241.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_empty_if_not_pdf(self):
start_time = time.time()
with self.assertRaises(Exception):
convert_from_path('./tests/test.jpg')
print('test_empty_if_not_pdf: {} sec'.format(time.time() - start_time))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_empty_if_file_not_found(self):
start_time = time.time()
with self.assertRaises(Exception):
convert_from_path('./tests/totally_a_real_file_in_folder.xyz')
print('test_empty_if_file_not_found: {} sec'.format(time.time() - start_time))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_empty_if_corrupted_pdf(self):
start_time = time.time()
with self.assertRaises(Exception):
convert_from_path('./tests/test_corrupted.pdf')
print('test_empty_if_corrupted_pdf: {} sec'.format(time.time() - start_time))
## Test first page
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_bytes_14_first_page_12(self):
start_time = time.time()
with open('./tests/test_14.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read(), first_page=12)
self.assertTrue(len(images_from_bytes) == 3)
print('test_conversion_from_bytes_14_last_page_12: {} sec'.format((time.time() - start_time) / 14.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_path_14_first_page_12(self):
start_time = time.time()
images_from_path = convert_from_path('./tests/test_14.pdf', first_page=12)
self.assertTrue(len(images_from_path) == 3)
print('test_conversion_from_path_14_first_page_12: {} sec'.format((time.time() - start_time) / 14.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_bytes_using_dir_14_first_page_12(self):
start_time = time.time()
with TemporaryDirectory() as path:
with open('./tests/test_14.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read(), output_folder=path, first_page=12)
self.assertTrue(len(images_from_bytes) == 3)
[im.close() for im in images_from_bytes]
print('test_conversion_from_bytes_using_dir_14_first_page_12: {} sec'.format((time.time() - start_time) / 14.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_path_using_dir_14_first_page_12(self):
start_time = time.time()
with TemporaryDirectory() as path:
images_from_path = convert_from_path('./tests/test_14.pdf', output_folder=path, first_page=12)
self.assertTrue(len(images_from_path) == 3)
[im.close() for im in images_from_path]
print('test_conversion_from_path_using_dir_14_first_page_12: {} sec'.format((time.time() - start_time) / 14.))
## Test last page
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_bytes_14_last_page_12(self):
start_time = time.time()
with open('./tests/test_14.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read(), last_page=12)
self.assertTrue(len(images_from_bytes) == 12)
print('test_conversion_from_bytes_14_last_page_12: {} sec'.format((time.time() - start_time) / 14.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_path_14_last_page_12(self):
start_time = time.time()
images_from_path = convert_from_path('./tests/test_14.pdf', last_page=12)
self.assertTrue(len(images_from_path) == 12)
print('test_conversion_from_path_14_last_page_12: {} sec'.format((time.time() - start_time) / 14.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_bytes_using_dir_14_last_page_12(self):
start_time = time.time()
with TemporaryDirectory() as path:
with open('./tests/test_14.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read(), output_folder=path, last_page=12)
self.assertTrue(len(images_from_bytes) == 12)
[im.close() for im in images_from_bytes]
print('test_conversion_from_bytes_using_dir_14_last_page_12: {} sec'.format((time.time() - start_time) / 14.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_path_using_dir_14_last_page_12(self):
start_time = time.time()
with TemporaryDirectory() as path:
images_from_path = convert_from_path('./tests/test_14.pdf', output_folder=path, last_page=12)
self.assertTrue(len(images_from_path) == 12)
[im.close() for im in images_from_path]
print('test_conversion_from_path_using_dir_14_last_page_12: {} sec'.format((time.time() - start_time) / 14.))
## Test first and last page
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_bytes_14_first_page_2_last_page_12(self):
start_time = time.time()
with open('./tests/test_14.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read(), first_page=2, last_page=12)
self.assertTrue(len(images_from_bytes) == 11)
print('test_conversion_from_bytes_14_first_page_2_last_page_12: {} sec'.format((time.time() - start_time) / 14.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_path_14_first_page_2_last_page_12(self):
start_time = time.time()
images_from_path = convert_from_path('./tests/test_14.pdf', first_page=2, last_page=12)
self.assertTrue(len(images_from_path) == 11)
print('test_conversion_from_path_14_first_page_2_last_page_12: {} sec'.format((time.time() - start_time) / 14.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_bytes_using_dir_14_first_page_2_last_page_12(self):
start_time = time.time()
with TemporaryDirectory() as path:
with open('./tests/test_14.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read(), output_folder=path, first_page=2, last_page=12)
self.assertTrue(len(images_from_bytes) == 11)
[im.close() for im in images_from_bytes]
print('test_conversion_from_bytes_using_dir_14_first_page_2_last_page_12: {} sec'.format((time.time() - start_time) / 14.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_path_using_dir_14_first_page_2_last_page_12(self):
start_time = time.time()
with TemporaryDirectory() as path:
images_from_path = convert_from_path('./tests/test_14.pdf', output_folder=path, first_page=2, last_page=12)
self.assertTrue(len(images_from_path) == 11)
[im.close() for im in images_from_path]
print('test_conversion_from_path_using_dir_14_first_page_2_last_page_12: {} sec'.format((time.time() - start_time) / 14.))
## Test output as jpeg
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_to_jpeg_from_bytes(self):
start_time = time.time()
with open('./tests/test.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read(), fmt='jpg')
self.assertTrue(images_from_bytes[0].format == 'JPEG')
print('test_conversion_to_jpeg_from_bytes_14: {} sec'.format((time.time() - start_time) / 14.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_to_jpeg_from_path_using_dir(self):
start_time = time.time()
with TemporaryDirectory() as path:
images_from_path = convert_from_path('./tests/test.pdf', output_folder=path, fmt='jpeg')
self.assertTrue(images_from_path[0].format == 'JPEG')
[im.close() for im in images_from_path]
print('test_conversion_to_jpeg_from_path_using_dir_14: {} sec'.format((time.time() - start_time) / 14.))
## Test output as png
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_to_png_from_bytes(self):
start_time = time.time()
with open('./tests/test.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read(), fmt='png')
self.assertTrue(images_from_bytes[0].format == 'PNG')
print('test_conversion_to_png_from_bytes_14: {} sec'.format((time.time() - start_time) / 14.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_to_png_from_path_using_dir(self):
start_time = time.time()
with TemporaryDirectory() as path:
images_from_path = convert_from_path('./tests/test.pdf', output_folder=path, fmt='png')
self.assertTrue(images_from_path[0].format == 'PNG')
[im.close() for im in images_from_path]
print('test_conversion_to_png_from_path_using_dir_14: {} sec'.format((time.time() - start_time) / 14.))
## Test output with not-empty output_folder
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_non_empty_output_folder(self):
start_time = time.time()
images_from_path = convert_from_path('./tests/test.pdf', output_folder='./tests/')
self.assertTrue(len(images_from_path) == 1)
[os.remove(im.filename) for im in images_from_path]
print('test_non_empty_output_folder: {} sec'.format((time.time() - start_time) / 14.))
## Test format that starts with a dot
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_format_that_starts_with_a_dot(self):
start_time = time.time()
with TemporaryDirectory() as path:
with open('./tests/test.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read(), output_folder=path, fmt='.jpg')
self.assertTrue(len(images_from_bytes) == 1)
[im.close() for im in images_from_bytes]
print('test_format_that_starts_with_a_dot: {} sec'.format(time.time() - start_time))
## Test locked PDF
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_locked_pdf_with_userpw_only(self):
start_time = time.time()
with TemporaryDirectory() as path:
with open('./tests/test_locked_user_only.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read(), output_folder=path, fmt='.jpg', userpw='pdf2image')
self.assertTrue(len(images_from_bytes) == 1)
[im.close() for im in images_from_bytes]
print('test_locked_pdf_with_userpw_only: {} sec'.format(time.time() - start_time))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_not_locked_pdf(self):
start_time = time.time()
with TemporaryDirectory() as path:
with open('./tests/test.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read(), output_folder=path, fmt='.jpg', userpw='pdf2image')
self.assertTrue(len(images_from_bytes) == 1)
[im.close() for im in images_from_bytes]
print('test_locked_pdf_with_userpw_only: {} sec'.format(time.time() - start_time))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_locked_pdf_with_ownerpw_only(self):
start_time = time.time()
with TemporaryDirectory() as path:
with open('./tests/test_locked_owner_only.pdf', 'rb') as pdf_file:
# No need to pass a ownerpw because the absence of userpw means we can read it anyway
images_from_bytes = convert_from_bytes(pdf_file.read(), output_folder=path, fmt='.jpg')
self.assertTrue(len(images_from_bytes) == 1)
[im.close() for im in images_from_bytes]
print('test_locked_pdf_with_ownerpw_only: {} sec'.format(time.time() - start_time))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_locked_pdf_with_ownerpw_and_userpw(self):
start_time = time.time()
with TemporaryDirectory() as path:
with open('./tests/test_locked_both.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read(), output_folder=path, fmt='.jpg', userpw='pdf2image')
self.assertTrue(len(images_from_bytes) == 1)
[im.close() for im in images_from_bytes]
print('test_locked_pdf_with_ownerpw_and_userpw: {} sec'.format(time.time() - start_time))
## Test multithreading
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_bytes_14_with_4_threads(self):
start_time = time.time()
with open('./tests/test_14.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read(), thread_count=4)
self.assertTrue(len(images_from_bytes) == 14)
print('test_conversion_from_bytes_14_with_4_thread: {} sec'.format((time.time() - start_time) / 14.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_path_14_with_4_threads(self):
start_time = time.time()
images_from_path = convert_from_path('./tests/test_14.pdf', thread_count=4)
self.assertTrue(len(images_from_path) == 14)
print('test_conversion_from_path_14_with_4_thread: {} sec'.format((time.time() - start_time) / 14.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_bytes_14_with_15_threads(self):
start_time = time.time()
with open('./tests/test_14.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read(), thread_count=15)
self.assertTrue(len(images_from_bytes) == 14)
print('test_conversion_from_bytes_14_with_15_thread: {} sec'.format((time.time() - start_time) / 14.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_path_14_with_0_threads(self):
start_time = time.time()
images_from_path = convert_from_path('./tests/test_14.pdf', thread_count=0)
self.assertTrue(len(images_from_path) == 14)
print('test_conversion_from_path_14_with_4_thread: {} sec'.format((time.time() - start_time) / 14.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_bytes_using_dir_14_with_4_threads(self):
start_time = time.time()
with TemporaryDirectory() as path:
with open('./tests/test_14.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read(), output_folder=path, thread_count=4)
self.assertTrue(len(images_from_bytes) == 14)
[im.close() for im in images_from_bytes]
print('test_conversion_from_bytes_using_dir_14_with_4_thread: {} sec'.format((time.time() - start_time) / 14.))
@profile
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_path_using_dir_14_with_4_threads(self):
start_time = time.time()
with TemporaryDirectory() as path:
images_from_path = convert_from_path('./tests/test_14.pdf', output_folder=path, thread_count=4)
self.assertTrue(len(images_from_path) == 14)
[im.close() for im in images_from_path]
print('test_conversion_from_path_using_dir_14_with_4_thread: {} sec'.format((time.time() - start_time) / 14.))
@profile
@unittest.skipIf("TRAVIS" in os.environ and os.environ["TRAVIS"] == "true", "Skipping this test on Travis CI.")
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_bytes_241_with_4_threads(self): # pragma: no cover
start_time = time.time()
with open('./tests/test_241.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read(), thread_count=4)
self.assertTrue(len(images_from_bytes) == 241)
print('test_conversion_from_bytes_241_with_4_thread: {} sec'.format((time.time() - start_time) / 241.))
@profile
@unittest.skipIf("TRAVIS" in os.environ and os.environ["TRAVIS"] == "true", "Skipping this test on Travis CI.")
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_path_241_with_4_threads(self): # pragma: no cover
start_time = time.time()
images_from_path = convert_from_path('./tests/test_241.pdf', thread_count=4)
self.assertTrue(len(images_from_path) == 241)
print('test_conversion_from_path_241_with_4_thread: {} sec'.format((time.time() - start_time) / 241.))
@profile
@unittest.skipIf("TRAVIS" in os.environ and os.environ["TRAVIS"] == "true", "Skipping this test on Travis CI.")
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_bytes_using_dir_241_with_4_threads(self): # pragma: no cover
start_time = time.time()
with TemporaryDirectory() as path:
with open('./tests/test_241.pdf', 'rb') as pdf_file:
images_from_bytes = convert_from_bytes(pdf_file.read(), output_folder=path, thread_count=4)
self.assertTrue(len(images_from_bytes) == 241)
[im.close() for im in images_from_bytes]
print('test_conversion_from_bytes_using_dir_241_with_4_thread: {} sec'.format((time.time() - start_time) / 241.))
@profile
@unittest.skipIf("TRAVIS" in os.environ and os.environ["TRAVIS"] == "true", "Skipping this test on Travis CI.")
@unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!")
def test_conversion_from_path_using_dir_241_with_4_threads(self): # pragma: no cover
start_time = time.time()
with TemporaryDirectory() as path:
images_from_path = convert_from_path('./tests/test_241.pdf', output_folder=path, thread_count=4)
self.assertTrue(len(images_from_path) == 241)
[im.close() for im in images_from_path]
print('test_conversion_from_path_using_dir_241_with_4_thread: {} sec'.format((time.time() - start_time) / 241.))
@unittest.skipIf(POPPLER_INSTALLED, "Poppler is installed, skipping.")
def test_pdfinfo_not_installed_throws(self):
start_time = time.time()
try:
images_from_path = convert_from_path('./tests/test_14.pdf')
raise Exception("This should not happen")
except:
pass
print('test_pdfinfo_not_installed_throws: {} sec'.format((time.time() - start_time) / 14.))
if __name__=='__main__':
unittest.main()