fix test suite
for the new jpg sample image
This commit is contained in:
parent
48f675db45
commit
002b2a28e1
Binary file not shown.
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
@ -169,8 +169,8 @@ class TestColour:
|
||||
|
||||
im = test.colourspace("cmyk").colourspace("srgb")
|
||||
|
||||
before = test(582, 210)
|
||||
after = im(582, 210)
|
||||
before = test(150, 210)
|
||||
after = im(150, 210)
|
||||
|
||||
assert_almost_equal_objects(before, after, threshold=10)
|
||||
|
||||
|
@ -124,11 +124,11 @@ class TestForeign:
|
||||
def test_jpeg(self):
|
||||
def jpeg_valid(im):
|
||||
a = im(10, 10)
|
||||
assert_almost_equal_objects(a, [6, 5, 3])
|
||||
assert_almost_equal_objects(a, [141, 127, 90])
|
||||
profile = im.get("icc-profile-data")
|
||||
assert len(profile) == 1352
|
||||
assert im.width == 1024
|
||||
assert im.height == 768
|
||||
assert len(profile) == 564
|
||||
assert im.width == 290
|
||||
assert im.height == 442
|
||||
assert im.bands == 3
|
||||
|
||||
self.file_loader("jpegload", JPEG_FILE, jpeg_valid)
|
||||
@ -726,10 +726,10 @@ class TestForeign:
|
||||
self.colour.dzsave(filename, suffix=".png")
|
||||
|
||||
# test horizontal overlap ... expect 256 step, overlap 1
|
||||
x = pyvips.Image.new_from_file(filename + "_files/10/0_0.png")
|
||||
x = pyvips.Image.new_from_file(filename + "_files/9/0_0.png")
|
||||
assert x.width == 255
|
||||
y = pyvips.Image.new_from_file(filename + "_files/10/1_0.png")
|
||||
assert y.width == 256
|
||||
y = pyvips.Image.new_from_file(filename + "_files/9/1_0.png")
|
||||
assert y.width == 37
|
||||
|
||||
# the right two columns of x should equal the left two columns of y
|
||||
left = x.crop(x.width - 2, 0, 2, x.height)
|
||||
@ -738,8 +738,8 @@ class TestForeign:
|
||||
|
||||
# test vertical overlap
|
||||
assert x.height == 255
|
||||
y = pyvips.Image.new_from_file(filename + "_files/10/0_1.png")
|
||||
assert y.height == 256
|
||||
y = pyvips.Image.new_from_file(filename + "_files/9/0_1.png")
|
||||
assert y.height == 189
|
||||
|
||||
# the bottom two rows of x should equal the top two rows of y
|
||||
top = x.crop(0, x.height - 2, x.width, 2)
|
||||
@ -751,19 +751,19 @@ class TestForeign:
|
||||
assert x.width == 1
|
||||
assert x.height == 1
|
||||
|
||||
# 10 should be the final layer
|
||||
assert not os.path.isdir(filename + "_files/11")
|
||||
# 9 should be the final layer
|
||||
assert not os.path.isdir(filename + "_files/10")
|
||||
|
||||
# default google layout
|
||||
filename = temp_filename(self.tempdir, '')
|
||||
self.colour.dzsave(filename, layout="google")
|
||||
|
||||
# test bottom-right tile ... default is 256x256 tiles, overlap 0
|
||||
x = pyvips.Image.new_from_file(filename + "/2/2/3.jpg")
|
||||
x = pyvips.Image.new_from_file(filename + "/1/1/1.jpg")
|
||||
assert x.width == 256
|
||||
assert x.height == 256
|
||||
assert not os.path.exists(filename + "/2/2/4.jpg")
|
||||
assert not os.path.exists(filename + "/3")
|
||||
assert not os.path.exists(filename + "/1/1/2.jpg")
|
||||
assert not os.path.exists(filename + "/2")
|
||||
x = pyvips.Image.new_from_file(filename + "/blank.png")
|
||||
assert x.width == 256
|
||||
assert x.height == 256
|
||||
@ -773,8 +773,10 @@ class TestForeign:
|
||||
# overlap 1, 510x510 pixels, 256 pixel tiles, should be exactly 2x2
|
||||
# tiles, though in fact the bottom and right edges will be white
|
||||
filename = temp_filename(self.tempdir, '')
|
||||
self.colour.crop(0, 0, 510, 510).dzsave(filename, layout="google",
|
||||
overlap=1, depth="one")
|
||||
self.colour \
|
||||
.replicate(2, 2) \
|
||||
.crop(0, 0, 510, 510) \
|
||||
.dzsave(filename, layout="google", overlap=1, depth="one")
|
||||
|
||||
x = pyvips.Image.new_from_file(filename + "/0/1/1.jpg")
|
||||
assert x.width == 256
|
||||
@ -784,8 +786,10 @@ class TestForeign:
|
||||
# with 511x511, it'll fit exactly into 2x2 -- we we actually generate
|
||||
# 3x3, since we output the overlaps
|
||||
filename = temp_filename(self.tempdir, '')
|
||||
self.colour.crop(0, 0, 511, 511).dzsave(filename, layout="google",
|
||||
overlap=1, depth="one")
|
||||
self.colour \
|
||||
.replicate(2, 2) \
|
||||
.crop(0, 0, 511, 511) \
|
||||
.dzsave(filename, layout="google", overlap=1, depth="one")
|
||||
|
||||
x = pyvips.Image.new_from_file(filename + "/0/2/2.jpg")
|
||||
assert x.width == 256
|
||||
@ -798,7 +802,7 @@ class TestForeign:
|
||||
|
||||
# 256x256 tiles, no overlap
|
||||
assert os.path.exists(filename + "/ImageProperties.xml")
|
||||
x = pyvips.Image.new_from_file(filename + "/TileGroup0/2-3-2.jpg")
|
||||
x = pyvips.Image.new_from_file(filename + "/TileGroup0/1-0-0.jpg")
|
||||
assert x.width == 256
|
||||
assert x.height == 256
|
||||
|
||||
@ -819,23 +823,23 @@ class TestForeign:
|
||||
filename = temp_filename(self.tempdir, '')
|
||||
self.colour.dzsave(filename, suffix=".png")
|
||||
|
||||
x = pyvips.Image.new_from_file(filename + "_files/10/0_0.png")
|
||||
x = pyvips.Image.new_from_file(filename + "_files/9/0_0.png")
|
||||
assert x.width == 255
|
||||
|
||||
# test overlap
|
||||
filename = temp_filename(self.tempdir, '')
|
||||
self.colour.dzsave(filename, overlap=200)
|
||||
|
||||
y = pyvips.Image.new_from_file(filename + "_files/10/1_1.jpeg")
|
||||
assert y.width == 654
|
||||
y = pyvips.Image.new_from_file(filename + "_files/9/1_1.jpeg")
|
||||
assert y.width == 236
|
||||
|
||||
# test tile-size
|
||||
filename = temp_filename(self.tempdir, '')
|
||||
self.colour.dzsave(filename, tile_size=512)
|
||||
|
||||
y = pyvips.Image.new_from_file(filename + "_files/10/0_0.jpeg")
|
||||
assert y.width == 513
|
||||
assert y.height == 513
|
||||
y = pyvips.Image.new_from_file(filename + "_files/9/0_0.jpeg")
|
||||
assert y.width == 290
|
||||
assert y.height == 442
|
||||
|
||||
# test save to memory buffer
|
||||
filename = temp_filename(self.tempdir, '.zip')
|
||||
|
@ -96,7 +96,7 @@ class TestHistogram:
|
||||
|
||||
ent = im.hist_find().hist_entropy()
|
||||
|
||||
assert pytest.approx(ent, 0.01) == 4.37
|
||||
assert pytest.approx(ent, 0.01) == 6.67
|
||||
|
||||
def test_stdif(self):
|
||||
im = pyvips.Image.new_from_file(JPEG_FILE)
|
||||
|
@ -103,8 +103,10 @@ class TestResample:
|
||||
def test_resize(self):
|
||||
im = pyvips.Image.new_from_file(JPEG_FILE)
|
||||
im2 = im.resize(0.25)
|
||||
assert im2.width == round(im.width / 4.0)
|
||||
assert im2.height == round(im.height / 4.0)
|
||||
# in py3, round() does not round to nearest in the obvious way, so we
|
||||
# have to do it by hand
|
||||
assert im2.width == int(im.width / 4.0 + 0.5)
|
||||
assert im2.height == int(im.height / 4.0 + 0.5)
|
||||
|
||||
# test geometry rounding corner case
|
||||
im = pyvips.Image.black(100, 1)
|
||||
@ -115,13 +117,15 @@ class TestResample:
|
||||
def test_shrink(self):
|
||||
im = pyvips.Image.new_from_file(JPEG_FILE)
|
||||
im2 = im.shrink(4, 4)
|
||||
assert im2.width == round(im.width / 4.0)
|
||||
assert im2.height == round(im.height / 4.0)
|
||||
# in py3, round() does not round to nearest in the obvious way, so we
|
||||
# have to do it by hand
|
||||
assert im2.width == int(im.width / 4.0 + 0.5)
|
||||
assert im2.height == int(im.height / 4.0 + 0.5)
|
||||
assert abs(im.avg() - im2.avg()) < 1
|
||||
|
||||
im2 = im.shrink(2.5, 2.5)
|
||||
assert im2.width == round(im.width / 2.5)
|
||||
assert im2.height == round(im.height / 2.5)
|
||||
assert im2.width == int(im.width / 2.5 + 0.5)
|
||||
assert im2.height == int(im.height / 2.5 + 0.5)
|
||||
assert abs(im.avg() - im2.avg()) < 1
|
||||
|
||||
@pytest.mark.skipif(not pyvips.at_least_libvips(8, 5),
|
||||
@ -129,7 +133,7 @@ class TestResample:
|
||||
def test_thumbnail(self):
|
||||
im = pyvips.Image.thumbnail(JPEG_FILE, 100)
|
||||
|
||||
assert im.width == 100
|
||||
assert im.height == 100
|
||||
assert im.bands == 3
|
||||
assert im.bands == 3
|
||||
|
||||
@ -138,9 +142,9 @@ class TestResample:
|
||||
assert abs(im_orig.avg() - im.avg()) < 1
|
||||
|
||||
# make sure we always get the right width
|
||||
for width in range(1000, 1, -13):
|
||||
im = pyvips.Image.thumbnail(JPEG_FILE, width)
|
||||
assert im.width == width
|
||||
for height in range(440, 1, -13):
|
||||
im = pyvips.Image.thumbnail(JPEG_FILE, height)
|
||||
assert im.height == height
|
||||
|
||||
# should fit one of width or height
|
||||
im = pyvips.Image.thumbnail(JPEG_FILE, 100, height=300)
|
||||
@ -196,7 +200,7 @@ class TestResample:
|
||||
# distorted, but the rest should not be too bad
|
||||
a = r.crop(50, 0, im.width - 50, im.height).gaussblur(2)
|
||||
b = im.crop(50, 0, im.width - 50, im.height).gaussblur(2)
|
||||
assert (a - b).abs().max() < 20
|
||||
assert (a - b).abs().max() < 40
|
||||
|
||||
# this was a bug at one point, strangely, if executed with debug
|
||||
# enabled
|
||||
|
@ -49,8 +49,8 @@ class TestStream:
|
||||
x = pyvips.Streami.new_from_file(JPEG_FILE)
|
||||
y = pyvips.Image.new_from_stream(x, "")
|
||||
|
||||
assert y.width == 1024
|
||||
assert y.height == 768
|
||||
assert y.width == 290
|
||||
assert y.height == 442
|
||||
|
||||
def test_streamo_new_to_file(self):
|
||||
filename = temp_filename(self.tempdir, ".jpg")
|
||||
@ -81,8 +81,8 @@ class TestStream:
|
||||
x = pyvips.Streami.new_from_memory(data)
|
||||
y = pyvips.Image.new_from_stream(x, "")
|
||||
|
||||
assert y.width == 1024
|
||||
assert y.height == 768
|
||||
assert y.width == 290
|
||||
assert y.height == 442
|
||||
|
||||
def test_streamo_new_memory(self):
|
||||
x = pyvips.Streamo.new_to_memory()
|
||||
|
Loading…
Reference in New Issue
Block a user