add a test for tuncated image files

This commit is contained in:
John Cupitt 2019-12-18 14:48:59 +00:00
parent 6b02c22457
commit 6c038f5ca8
3 changed files with 15 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import pyvips
IMAGES = os.path.join(os.path.dirname(__file__), os.pardir, 'images')
JPEG_FILE = os.path.join(IMAGES, "sample.jpg")
TRUNCATED_FILE = os.path.join(IMAGES, "truncated.jpg")
SRGB_FILE = os.path.join(IMAGES, "sRGB.icm")
MATLAB_FILE = os.path.join(IMAGES, "sample.mat")
PNG_FILE = os.path.join(IMAGES, "sample.png")

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

View File

@ -11,7 +11,7 @@ from helpers import \
JPEG_FILE, SRGB_FILE, MATLAB_FILE, PNG_FILE, TIF_FILE, OME_FILE, \
ANALYZE_FILE, GIF_FILE, WEBP_FILE, EXR_FILE, FITS_FILE, OPENSLIDE_FILE, \
PDF_FILE, SVG_FILE, SVGZ_FILE, SVG_GZ_FILE, GIF_ANIM_FILE, DICOM_FILE, \
BMP_FILE, NIFTI_FILE, ICO_FILE, HEIC_FILE, \
BMP_FILE, NIFTI_FILE, ICO_FILE, HEIC_FILE, TRUNCATED_FILE, \
temp_filename, assert_almost_equal_objects, have, skip_if_no
@ -234,6 +234,19 @@ class TestForeign:
# format area at the end
assert y.startswith("hello world")
@skip_if_no("jpegload")
def test_truncated(self):
# This should open (there's enough there for the header)
im = pyvips.Image.new_from_file(TRUNCATED_FILE)
# but this should fail with a warning, and knock TRUNCATED_FILE out of
# the cache
x = im.avg()
# now we should open again, but it won't come from cache, it'll reload
im = pyvips.Image.new_from_file(TRUNCATED_FILE)
# and this should fail with a warning once more
x = im.avg()
@skip_if_no("pngload")
def test_png(self):
def png_valid(im):