def test_leptonica_compile(tmpdir): from ocrmypdf.lib.compile_leptonica import ffibuilder # Compile the library but build it somewhere that won't interfere with # existing compiled library. Also compile in API mode so that we test # the interfaces, even though we use it ABI mode. ffibuilder.compile(tmpdir=fspath(tmpdir), target=fspath(tmpdir / 'lepttest.*'))
def test_srgb_in_unicode_path(tmpdir): """Test that we can produce pdfmark when install path is not ASCII""" dstdir = Path(fspath(tmpdir)) / b'\xe4\x80\x80'.decode('utf-8') dstdir.mkdir() dst = dstdir / 'sRGB.icc' copyfile(SRGB_ICC_PROFILE, fspath(dst)) with patch('ocrmypdf.pdfa.SRGB_ICC_PROFILE', new=str(dst)): generate_pdfa_ps(dstdir / 'out.ps', {})
def test_no_languages(ensure_tess4, tmpdir): env = ensure_tess4 (tmpdir / 'tessdata').mkdir() env['TESSDATA_PREFIX'] = fspath(tmpdir) with modified_os_environ(env): with pytest.raises(MissingDependencyError): tesseract.languages.cache_clear() tesseract.languages()
def test_flate_to_jbig2(resources, outdir, spoof_tesseract_noop): # This test requires an image that pngquant is capable of converting to # to 1bpp - so use an existing 1bpp image, convert up, confirm it can # convert down im = Image.open(fspath(resources / 'typewriter.png')) assert im.mode in ('1', 'P') im = im.convert('L') im.save(fspath(outdir / 'type8.png')) check_ocrmypdf(outdir / 'type8.png', outdir / 'out.pdf', '--image-dpi', '100', '--png-quality', '10', '--optimize', '3', env=spoof_tesseract_noop) pdf = pikepdf.open(outdir / 'out.pdf') pim = pikepdf.PdfImage(next(iter(pdf.pages[0].images.values()))) assert pim.filters[0] == '/JBIG2Decode'
def test_mono_not_inverted(resources, outdir): infile = resources / '2400dpi.pdf' opt.main(infile, outdir / 'out.pdf', level=3) rasterize_pdf(outdir / 'out.pdf', outdir / 'im.png', xres=10, yres=10, raster_device='pnggray', log=logging.getLogger(name='test_mono_flip')) im = Image.open(fspath(outdir / 'im.png')) assert im.getpixel((0, 0)) == 255, "Expected white background"
def make_rotate_test(prefix, image_angle, page_angle): im = Image.open(fspath(resources / 'typewriter.png')) if image_angle != 0: ccw_angle = -image_angle % 360 im = im.transpose(getattr(Image, 'ROTATE_{}'.format(ccw_angle))) memimg = BytesIO() im.save(memimg, format='PNG') memimg.seek(0) mempdf = BytesIO() img2pdf.convert(memimg.read(), layout_fun=img2pdf.get_fixed_dpi_layout_fun( (200, 200)), outputstream=mempdf) mempdf.seek(0) pike = pikepdf.open(mempdf) pike.pages[0].Rotate = page_angle target = outdir / '{}_{}_{}.pdf'.format(prefix, image_angle, page_angle) pike.save(target) return target