| 70 | |
| 71 | |
| 72 | class PDFConversionMethods(unittest.TestCase): |
| 73 | @unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!") |
| 74 | def test_hyphen_prefixed_pdf_paths(self): |
| 75 | source = os.path.abspath("./tests/test.pdf") |
| 76 | cwd = os.getcwd() |
| 77 | with TemporaryDirectory() as directory: |
| 78 | shutil.copyfile(source, os.path.join(directory, "-v")) |
| 79 | try: |
| 80 | os.chdir(directory) |
| 81 | for path in ("-v", "./-v", pathlib.Path("-v")): |
| 82 | with self.subTest(path=path, operation="pdfinfo"): |
| 83 | self.assertEqual(pdfinfo_from_path(path)["Pages"], 1) |
| 84 | for use_pdftocairo in (False, True): |
| 85 | with self.subTest(path=path, use_pdftocairo=use_pdftocairo): |
| 86 | images = convert_from_path( |
| 87 | path, dpi=30, use_pdftocairo=use_pdftocairo |
| 88 | ) |
| 89 | try: |
| 90 | self.assertEqual(len(images), 1) |
| 91 | self.assertGreater(images[0].width, 0) |
| 92 | finally: |
| 93 | for image in images: |
| 94 | image.close() |
| 95 | finally: |
| 96 | os.chdir(cwd) |
| 97 | |
| 98 | @profile |
| 99 | @unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!") |
| 100 | def test_conversion_from_bytes(self): |
| 101 | start_time = time.time() |
| 102 | with open("./tests/test.pdf", "rb") as pdf_file: |
| 103 | images_from_bytes = convert_from_bytes(pdf_file.read()) |
| 104 | self.assertTrue(len(images_from_bytes) == 1) |
| 105 | print("test_conversion_from_bytes: {} sec".format(time.time() - start_time)) |
| 106 | |
| 107 | @profile |
| 108 | @unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!") |
| 109 | def test_conversion_from_path(self): |
| 110 | start_time = time.time() |
| 111 | images_from_path = convert_from_path("./tests/test.pdf") |
| 112 | self.assertTrue(len(images_from_path) == 1) |
| 113 | print("test_conversion_from_path: {} sec".format(time.time() - start_time)) |
| 114 | |
| 115 | @profile |
| 116 | @unittest.skipIf(not POPPLER_INSTALLED, "Poppler is not installed!") |
| 117 | def test_conversion_from_bytes_using_dir(self): |
| 118 | start_time = time.time() |
| 119 | with TemporaryDirectory() as path: |
| 120 | with open("./tests/test.pdf", "rb") as pdf_file: |
| 121 | images_from_bytes = convert_from_bytes( |
| 122 | pdf_file.read(), output_folder=path |
| 123 | ) |
| 124 | self.assertTrue(len(images_from_bytes) == 1) |
| 125 | [im.close() for im in images_from_bytes] |
| 126 | print( |
| 127 | "test_conversion_from_bytes_using_dir: {} sec".format( |
| 128 | time.time() - start_time |
| 129 | ) |
nothing calls this directly
no outgoing calls
no test coverage detected