diff --git a/test/test-suite/helpers/helpers.py b/test/test-suite/helpers/helpers.py index 628e9935..68343d00 100644 --- a/test/test-suite/helpers/helpers.py +++ b/test/test-suite/helpers/helpers.py @@ -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") diff --git a/test/test-suite/images/truncated.jpg b/test/test-suite/images/truncated.jpg new file mode 100644 index 00000000..71ae0bb4 Binary files /dev/null and b/test/test-suite/images/truncated.jpg differ diff --git a/test/test-suite/test_foreign.py b/test/test-suite/test_foreign.py index a45da51b..94b4336b 100644 --- a/test/test-suite/test_foreign.py +++ b/test/test-suite/test_foreign.py @@ -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):