coverage: improve leptonic; don't create objects with null pointers
This commit is contained in:
+51
-1
@@ -18,8 +18,12 @@
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import pytest
|
||||
import sys
|
||||
from pickle import dumps, loads
|
||||
|
||||
import pytest
|
||||
from PIL import Image, ImageChops
|
||||
|
||||
import ocrmypdf.leptonica as lept
|
||||
|
||||
|
||||
@@ -28,3 +32,49 @@ def test_colormap_backgroundnorm(resources):
|
||||
# can handle that case
|
||||
pix = lept.Pix.open(resources / 'baiona_colormapped.png')
|
||||
pix.background_norm()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def crom_pix(resources):
|
||||
pix = lept.Pix.open(resources / 'crom.png')
|
||||
im = Image.open(resources / 'crom.png')
|
||||
return pix, im
|
||||
|
||||
|
||||
def test_pix_basic(crom_pix):
|
||||
pix, im = crom_pix
|
||||
|
||||
assert pix.width == im.width
|
||||
assert pix.height == im.height
|
||||
assert pix.mode == im.mode
|
||||
|
||||
|
||||
def test_pil_conversion(crom_pix):
|
||||
pix, im = crom_pix
|
||||
|
||||
# Check for pixel perfect
|
||||
assert ImageChops.difference(pix.topil(), im).getbbox() is None
|
||||
|
||||
|
||||
def test_pix_otsu(crom_pix):
|
||||
pix, _ = crom_pix
|
||||
im1bpp = pix.otsu_adaptive_threshold()
|
||||
assert im1bpp.mode == '1'
|
||||
|
||||
|
||||
def test_crop(resources):
|
||||
pix = lept.Pix.open(resources / 'linn.png')
|
||||
foreground = pix.crop_to_foreground()
|
||||
assert foreground.width < pix.width
|
||||
|
||||
|
||||
def test_clean_bg(crom_pix):
|
||||
pix, _ = crom_pix
|
||||
imbg = pix.clean_background_to_white()
|
||||
|
||||
|
||||
def test_pickle(crom_pix):
|
||||
pix, _ = crom_pix
|
||||
pickled = dumps(pix)
|
||||
pix2 = loads(pickled)
|
||||
assert pix.mode == pix2.mode
|
||||
|
||||
Reference in New Issue
Block a user