diff --git a/tests/python_tests/webp_encoding_test.py b/tests/python_tests/webp_encoding_test.py index 933bb238c..ed6e57745 100644 --- a/tests/python_tests/webp_encoding_test.py +++ b/tests/python_tests/webp_encoding_test.py @@ -64,91 +64,97 @@ if mapnik.has_webp(): def test_expected_encodings(): fails = [] - for opt in opts: - im = mapnik.Image(256,256) - expected = gen_filepath('blank',opt) - actual = os.path.join(tmp_dir,os.path.basename(expected)) - if generate or not os.path.exists(expected): - print 'generating expected image %s' % expected - im.save(expected,opt) - im.save(actual,opt) - try: - expected_bytes = mapnik.Image.open(expected).tostring() - except RuntimeError: - # this will happen if libweb is old, since it cannot open images created by more recent webp - print 'warning, cannot open webp expected image (your libwebp is likely too old)' - continue - if mapnik.Image.open(actual).tostring() != expected_bytes: - fails.append('%s (actual) not == to %s (expected)' % (actual,expected)) + try: + for opt in opts: + im = mapnik.Image(256,256) + expected = gen_filepath('blank',opt) + actual = os.path.join(tmp_dir,os.path.basename(expected)) + if generate or not os.path.exists(expected): + print 'generating expected image %s' % expected + im.save(expected,opt) + im.save(actual,opt) + try: + expected_bytes = mapnik.Image.open(expected).tostring() + except RuntimeError: + # this will happen if libweb is old, since it cannot open images created by more recent webp + print 'warning, cannot open webp expected image (your libwebp is likely too old)' + continue + if mapnik.Image.open(actual).tostring() != expected_bytes: + fails.append('%s (actual) not == to %s (expected)' % (actual,expected)) - for opt in opts: - im = mapnik.Image(256,256) - im.background = mapnik.Color('green') - expected = gen_filepath('solid',opt) - actual = os.path.join(tmp_dir,os.path.basename(expected)) - if generate or not os.path.exists(expected): - print 'generating expected image %s' % expected - im.save(expected,opt) - im.save(actual,opt) - try: - expected_bytes = mapnik.Image.open(expected).tostring() - except RuntimeError: - # this will happen if libweb is old, since it cannot open images created by more recent webp - print 'warning, cannot open webp expected image (your libwebp is likely too old)' - continue - if mapnik.Image.open(actual).tostring() != expected_bytes: - fails.append('%s (actual) not == to %s (expected)' % (actual,expected)) + for opt in opts: + im = mapnik.Image(256,256) + im.background = mapnik.Color('green') + expected = gen_filepath('solid',opt) + actual = os.path.join(tmp_dir,os.path.basename(expected)) + if generate or not os.path.exists(expected): + print 'generating expected image %s' % expected + im.save(expected,opt) + im.save(actual,opt) + try: + expected_bytes = mapnik.Image.open(expected).tostring() + except RuntimeError: + # this will happen if libweb is old, since it cannot open images created by more recent webp + print 'warning, cannot open webp expected image (your libwebp is likely too old)' + continue + if mapnik.Image.open(actual).tostring() != expected_bytes: + fails.append('%s (actual) not == to %s (expected)' % (actual,expected)) - for opt in opts: - im = mapnik.Image.open('images/support/transparency/aerial_rgba.png') - expected = gen_filepath('aerial_rgba',opt) - actual = os.path.join(tmp_dir,os.path.basename(expected)) - if generate or not os.path.exists(expected): - print 'generating expected image %s' % expected - im.save(expected,opt) - im.save(actual,opt) - try: - expected_bytes = mapnik.Image.open(expected).tostring() - except RuntimeError: - # this will happen if libweb is old, since it cannot open images created by more recent webp - print 'warning, cannot open webp expected image (your libwebp is likely too old)' - continue - if mapnik.Image.open(actual).tostring() != expected_bytes: - fails.append('%s (actual) not == to %s (expected)' % (actual,expected)) - # disabled to avoid failures on ubuntu when using old webp packages - #eq_(fails,[],'\n'+'\n'.join(fails)) + for opt in opts: + im = mapnik.Image.open('images/support/transparency/aerial_rgba.png') + expected = gen_filepath('aerial_rgba',opt) + actual = os.path.join(tmp_dir,os.path.basename(expected)) + if generate or not os.path.exists(expected): + print 'generating expected image %s' % expected + im.save(expected,opt) + im.save(actual,opt) + try: + expected_bytes = mapnik.Image.open(expected).tostring() + except RuntimeError: + # this will happen if libweb is old, since it cannot open images created by more recent webp + print 'warning, cannot open webp expected image (your libwebp is likely too old)' + continue + if mapnik.Image.open(actual).tostring() != expected_bytes: + fails.append('%s (actual) not == to %s (expected)' % (actual,expected)) + # disabled to avoid failures on ubuntu when using old webp packages + #eq_(fails,[],'\n'+'\n'.join(fails)) + except RuntimeError, e: + print e def test_transparency_levels(): - # create partial transparency image - im = mapnik.Image(256,256) - im.background = mapnik.Color('rgba(255,255,255,.5)') - c2 = mapnik.Color('rgba(255,255,0,.2)') - c3 = mapnik.Color('rgb(0,255,255)') - for y in range(0,im.height()/2): - for x in range(0,im.width()/2): - im.set_pixel(x,y,c2) - for y in range(im.height()/2,im.height()): - for x in range(im.width()/2,im.width()): - im.set_pixel(x,y,c3) - - t0 = tmp_dir + 'white0-actual.webp' - - # octree - format = 'webp' - expected = 'images/support/transparency/white0.webp' - if generate or not os.path.exists(expected): - im.save('images/support/transparency/white0.webp') - im.save(t0,format) - im_in = mapnik.Image.open(t0) - t0_len = len(im_in.tostring(format)) try: - expected_bytes = mapnik.Image.open(expected).tostring(format) - except RuntimeError: - # this will happen if libweb is old, since it cannot open images created by more recent webp - print 'warning, cannot open webp expected image (your libwebp is likely too old)' - return - # disabled to avoid failures on ubuntu when using old webp packages - #eq_(t0_len,len(expected_bytes)) + # create partial transparency image + im = mapnik.Image(256,256) + im.background = mapnik.Color('rgba(255,255,255,.5)') + c2 = mapnik.Color('rgba(255,255,0,.2)') + c3 = mapnik.Color('rgb(0,255,255)') + for y in range(0,im.height()/2): + for x in range(0,im.width()/2): + im.set_pixel(x,y,c2) + for y in range(im.height()/2,im.height()): + for x in range(im.width()/2,im.width()): + im.set_pixel(x,y,c3) + + t0 = tmp_dir + 'white0-actual.webp' + + # octree + format = 'webp' + expected = 'images/support/transparency/white0.webp' + if generate or not os.path.exists(expected): + im.save('images/support/transparency/white0.webp') + im.save(t0,format) + im_in = mapnik.Image.open(t0) + t0_len = len(im_in.tostring(format)) + try: + expected_bytes = mapnik.Image.open(expected).tostring(format) + except RuntimeError: + # this will happen if libweb is old, since it cannot open images created by more recent webp + print 'warning, cannot open webp expected image (your libwebp is likely too old)' + return + # disabled to avoid failures on ubuntu when using old webp packages + #eq_(t0_len,len(expected_bytes)) + except RuntimeError, e: + print e if __name__ == "__main__":