mapnik/tests/python_tests/compositing_test.py

39 lines
1.4 KiB
Python
Raw Normal View History

2012-03-24 00:36:37 +00:00
#encoding: utf8
from nose.tools import *
import os,sys
from utilities import execution_path
from utilities import Todo
import mapnik
def setup():
# All of the paths used are relative, if we run the tests
# from another directory we need to chdir()
os.chdir(execution_path('.'))
def test_compare_images():
b = mapnik.Image.open('./images/support/b.png')
b.premultiply()
2012-03-24 00:36:37 +00:00
for name in mapnik.CompositeOp.names:
a = mapnik.Image.open('./images/support/a.png')
a.premultiply()
2012-03-24 00:36:37 +00:00
a.composite(b,getattr(mapnik.CompositeOp,name))
actual = '/tmp/mapnik-comp-op-test-' + name + '.png'
expected = 'images/composited/' + name + '.png'
a.demultiply()
2012-03-24 00:36:37 +00:00
a.save(actual)
expected_im = mapnik.Image.open(expected)
# compare them
eq_(a.tostring(),expected_im.tostring(), 'failed comparing actual (%s) and expected(%s)' % (actual,'tests/python_tests/'+ expected))
b.demultiply()
# b will be slightly modified by pre and then de multiplication rounding errors
# TODO - write test to ensure the image is 99% the same.
#expected_b = mapnik.Image.open('./images/support/b.png')
#b.save('/tmp/mapnik-comp-op-test-original-mask.png')
#eq_(b.tostring(),expected_b.tostring(), '/tmp/mapnik-comp-op-test-original-mask.png is no longer equivalent to original mask: ./images/support/b.png')
2012-03-24 00:36:37 +00:00
if __name__ == "__main__":
setup()
[eval(run)() for run in dir() if 'test_' in run]