test region_shrink

just sets the option, does not verify accuracy :(
This commit is contained in:
John Cupitt 2018-07-07 17:07:35 +01:00
parent 92ff5be4b8
commit 2695916afb
2 changed files with 121 additions and 124 deletions

View File

@ -72,6 +72,10 @@ Run the libvips test suite with:
$ pytest $ pytest
Run a specific test with:
$ pytest test/test-suite/test_foreign.py -k test_tiff
YOu will need to install a variety of Python packages for this, including YOu will need to install a variety of Python packages for this, including
pyvips, the libvips Python binding. pyvips, the libvips Python binding.

View File

@ -320,7 +320,6 @@ class TestForeign:
assert x1.height == x2.width assert x1.height == x2.width
# OME support in 8.5 # OME support in 8.5
if pyvips.at_least_libvips(8, 5):
x = pyvips.Image.new_from_file(OME_FILE) x = pyvips.Image.new_from_file(OME_FILE)
assert x.width == 439 assert x.width == 439
assert x.height == 167 assert x.height == 167
@ -354,7 +353,6 @@ class TestForeign:
assert x(0, 168)[0] == 1 assert x(0, 168)[0] == 1
# pyr save to buffer added in 8.6 # pyr save to buffer added in 8.6
if pyvips.at_least_libvips(8, 6):
x = pyvips.Image.new_from_file(TIF_FILE) x = pyvips.Image.new_from_file(TIF_FILE)
buf = x.tiffsave_buffer(tile=True, pyramid=True) buf = x.tiffsave_buffer(tile=True, pyramid=True)
filename = temp_filename(self.tempdir, '.tif') filename = temp_filename(self.tempdir, '.tif')
@ -369,6 +367,12 @@ class TestForeign:
assert a.height == b.height assert a.height == b.height
assert a.avg() == b.avg() assert a.avg() == b.avg()
# region-shrink added in 8.7
x = pyvips.Image.new_from_file(TIF_FILE)
buf = x.tiffsave_buffer(tile=True, pyramid=True, region_shrink="mean")
buf = x.tiffsave_buffer(tile=True, pyramid=True, region_shrink="mode")
buf = x.tiffsave_buffer(tile=True, pyramid=True, region_shrink="median")
@skip_if_no("magickload") @skip_if_no("magickload")
def test_magickload(self): def test_magickload(self):
def bmp_valid(im): def bmp_valid(im):
@ -637,7 +641,7 @@ class TestForeign:
self.save_buffer_tempfile("radsave_buffer", ".hdr", self.save_buffer_tempfile("radsave_buffer", ".hdr",
self.rad, max_diff=0) self.rad, max_diff=0)
@skip_if_no("dzsaveload") @skip_if_no("dzsave")
def test_dzsave(self): def test_dzsave(self):
# dzsave is hard to test, there are so many options # dzsave is hard to test, there are so many options
# test each option separately and hope they all function together # test each option separately and hope they all function together
@ -706,8 +710,6 @@ class TestForeign:
# with 511x511, it'll fit exactly into 2x2 -- we we actually generate # with 511x511, it'll fit exactly into 2x2 -- we we actually generate
# 3x3, since we output the overlaps # 3x3, since we output the overlaps
# 8.6 revised the rules on overlaps, so don't test earlier than that
if pyvips.base.at_least_libvips(8, 6):
filename = temp_filename(self.tempdir, '') filename = temp_filename(self.tempdir, '')
self.colour.crop(0, 0, 511, 511).dzsave(filename, layout="google", self.colour.crop(0, 0, 511, 511).dzsave(filename, layout="google",
overlap=1, depth="one") overlap=1, depth="one")
@ -730,10 +732,6 @@ class TestForeign:
# test zip output # test zip output
filename = temp_filename(self.tempdir, '.zip') filename = temp_filename(self.tempdir, '.zip')
self.colour.dzsave(filename) self.colour.dzsave(filename)
# before 8.5.8, you needed a gc on pypy to flush small zip output to
# disc
if not pyvips.base.at_least_libvips(8, 6):
gc.collect()
assert os.path.exists(filename) assert os.path.exists(filename)
assert not os.path.exists(filename + "_files") assert not os.path.exists(filename + "_files")
assert not os.path.exists(filename + ".dzi") assert not os.path.exists(filename + ".dzi")
@ -741,10 +739,6 @@ class TestForeign:
# test compressed zip output # test compressed zip output
filename2 = temp_filename(self.tempdir, '.zip') filename2 = temp_filename(self.tempdir, '.zip')
self.colour.dzsave(filename2, compression=-1) self.colour.dzsave(filename2, compression=-1)
# before 8.5.8, you needed a gc on pypy to flush small zip output to
# disc
if not pyvips.base.at_least_libvips(8, 6):
gc.collect()
assert os.path.exists(filename2) assert os.path.exists(filename2)
assert os.path.getsize(filename2) < os.path.getsize(filename) assert os.path.getsize(filename2) < os.path.getsize(filename)
@ -771,16 +765,11 @@ class TestForeign:
assert y.height == 513 assert y.height == 513
# test save to memory buffer # test save to memory buffer
if have("dzsave_buffer"):
filename = temp_filename(self.tempdir, '.zip') filename = temp_filename(self.tempdir, '.zip')
base = os.path.basename(filename) base = os.path.basename(filename)
root, ext = os.path.splitext(base) root, ext = os.path.splitext(base)
self.colour.dzsave(filename) self.colour.dzsave(filename)
# before 8.5.8, you needed a gc on pypy to flush small zip
# output to disc
if not pyvips.base.at_least_libvips(8, 6):
gc.collect()
with open(filename, 'rb') as f: with open(filename, 'rb') as f:
buf1 = f.read() buf1 = f.read()
buf2 = self.colour.dzsave_buffer(basename=root) buf2 = self.colour.dzsave_buffer(basename=root)
@ -789,6 +778,10 @@ class TestForeign:
# we can't test the bytes are exactly equal -- the timestamps will # we can't test the bytes are exactly equal -- the timestamps will
# be different # be different
# added in 8.7
buf = self.colour.dzsave_buffer(region_shrink="mean")
buf = self.colour.dzsave_buffer(region_shrink="mode")
buf = self.colour.dzsave_buffer(region_shrink="median")
if __name__ == '__main__': if __name__ == '__main__':
pytest.main() pytest.main()