def test_compare_images(): b = mapnik.Image.open('./images/support/b.png') b.premultiply() num_ops = len(mapnik.CompositeOp.names) successes = [] fails = [] for name in mapnik.CompositeOp.names: a = mapnik.Image.open('./images/support/a.png') a.premultiply() a.composite(b,getattr(mapnik.CompositeOp,name)) actual = '/tmp/mapnik-comp-op-test-' + name + '.png' expected = 'images/composited/' + name + '.png' valid = validate_pixels_are_premultiplied(a) if not valid[0]: fails.append('%s not validly premultiplied!:\n\t %s pixels (%s)' % (name,len(valid[1]),valid[1][0])) a.demultiply() if not validate_pixels_are_not_premultiplied(a): fails.append('%s not validly demultiplied' % (name)) a.save(actual) if not os.path.exists(expected): print 'generating expected test image: %s' % expected a.save(expected) expected_im = mapnik.Image.open(expected) # compare them if a.tostring() == expected_im.tostring(): successes.append(name) else: fails.append('failed comparing actual (%s) and expected(%s)' % (actual,'tests/python_tests/'+ expected)) fail_im = side_by_side_image(expected_im, a) fail_im.save('/tmp/mapnik-comp-op-test-' + name + '.fail.png') eq_(len(successes),num_ops,'\n'+'\n'.join(fails)) b.demultiply()
def test_compare_images(): b = mapnik.Image.open('./images/support/b.png') b.premultiply() num_ops = len(mapnik.CompositeOp.names) successes = [] fails = [] for name in mapnik.CompositeOp.names: a = mapnik.Image.open('./images/support/a.png') a.premultiply() a.composite(b, getattr(mapnik.CompositeOp, name)) actual = '/tmp/mapnik-comp-op-test-' + name + '.png' expected = 'images/composited/' + name + '.png' valid = validate_pixels_are_premultiplied(a) if not valid[0]: fails.append('%s not validly premultiplied!:\n\t %s pixels (%s)' % (name, len(valid[1]), valid[1][0])) a.demultiply() if not validate_pixels_are_not_premultiplied(a): fails.append('%s not validly demultiplied' % (name)) a.save(actual, 'png32') if not os.path.exists(expected) or os.environ.get('UPDATE'): print 'generating expected test image: %s' % expected a.save(expected, 'png32') expected_im = mapnik.Image.open(expected) # compare them if a.tostring('png32') == expected_im.tostring('png32'): successes.append(name) else: fails.append('failed comparing actual (%s) and expected(%s)' % (actual, 'tests/python_tests/' + expected)) fail_im = side_by_side_image(expected_im, a) fail_im.save('/tmp/mapnik-comp-op-test-' + name + '.fail.png', 'png32') eq_(len(successes), num_ops, '\n' + '\n'.join(fails)) b.demultiply()
def test_style_level_comp_op(): m = mapnik.Map(256, 256) mapnik.load_map(m, '../data/good_maps/style_level_comp_op.xml') m.zoom_all() successes = [] fails = [] for name in mapnik.CompositeOp.names: # find_style returns a copy of the style object style_markers = m.find_style("markers") style_markers.comp_op = getattr(mapnik.CompositeOp, name) # replace the original style with the modified one replace_style(m, "markers", style_markers) im = mapnik.Image(m.width, m.height) mapnik.render(m, im) actual = '/tmp/mapnik-style-comp-op-' + name + '.png' expected = 'images/style-comp-op/' + name + '.png' im.save(actual) if not os.path.exists(expected): print 'generating expected test image: %s' % expected im.save(expected) expected_im = mapnik.Image.open(expected) # compare them if im.tostring() == expected_im.tostring(): successes.append(name) else: fails.append('failed comparing actual (%s) and expected(%s)' % (actual,'tests/python_tests/'+ expected)) fail_im = side_by_side_image(expected_im, im) fail_im.save('/tmp/mapnik-style-comp-op-' + name + '.fail.png') eq_(len(fails), 0, '\n'+'\n'.join(fails))
def test_compare_images(): b = mapnik.Image.open("./images/support/b.png") b.premultiply() num_ops = len(mapnik.CompositeOp.names) successes = [] fails = [] for name in mapnik.CompositeOp.names: a = mapnik.Image.open("./images/support/a.png") a.premultiply() a.composite(b, getattr(mapnik.CompositeOp, name)) actual = "/tmp/mapnik-comp-op-test-" + name + ".png" expected = "images/composited/" + name + ".png" valid = validate_pixels_are_premultiplied(a) if not valid[0]: fails.append("%s not validly premultiplied!:\n\t %s pixels (%s)" % (name, len(valid[1]), valid[1][0])) a.demultiply() if not validate_pixels_are_not_premultiplied(a): fails.append("%s not validly demultiplied" % (name)) a.save(actual, "png32") if not os.path.exists(expected) or os.environ.get("UPDATE"): print "generating expected test image: %s" % expected a.save(expected, "png32") expected_im = mapnik.Image.open(expected) # compare them if a.tostring("png32") == expected_im.tostring("png32"): successes.append(name) else: fails.append("failed comparing actual (%s) and expected(%s)" % (actual, "tests/python_tests/" + expected)) fail_im = side_by_side_image(expected_im, a) fail_im.save("/tmp/mapnik-comp-op-test-" + name + ".fail.png", "png32") eq_(len(successes), num_ops, "\n" + "\n".join(fails)) b.demultiply()
def test_style_level_comp_op(): m = mapnik.Map(256, 256) mapnik.load_map(m, '../data/good_maps/style_level_comp_op.xml') m.zoom_all() successes = [] fails = [] for name in mapnik.CompositeOp.names: # find_style returns a copy of the style object style_markers = m.find_style("markers") style_markers.comp_op = getattr(mapnik.CompositeOp, name) # replace the original style with the modified one replace_style(m, "markers", style_markers) im = mapnik.Image(m.width, m.height) mapnik.render(m, im) actual = '/tmp/mapnik-style-comp-op-' + name + '.png' expected = 'images/style-comp-op/' + name + '.png' im.save(actual, 'png32') if not os.path.exists(expected) or os.environ.get('UPDATE'): print 'generating expected test image: %s' % expected im.save(expected, 'png32') expected_im = mapnik.Image.open(expected) # compare them if im.tostring('png32') == expected_im.tostring('png32'): successes.append(name) else: fails.append('failed comparing actual (%s) and expected(%s)' % (actual, 'tests/python_tests/' + expected)) fail_im = side_by_side_image(expected_im, im) fail_im.save('/tmp/mapnik-style-comp-op-' + name + '.fail.png', 'png32') eq_(len(fails), 0, '\n' + '\n'.join(fails))
def test_style_level_comp_op(): m = mapnik.Map(256, 256) mapnik.load_map(m, "../data/good_maps/style_level_comp_op.xml") m.zoom_all() successes = [] fails = [] for name in mapnik.CompositeOp.names: # find_style returns a copy of the style object style_markers = m.find_style("markers") style_markers.comp_op = getattr(mapnik.CompositeOp, name) # replace the original style with the modified one replace_style(m, "markers", style_markers) im = mapnik.Image(m.width, m.height) mapnik.render(m, im) actual = "/tmp/mapnik-style-comp-op-" + name + ".png" expected = "images/style-comp-op/" + name + ".png" im.save(actual, "png32") if not os.path.exists(expected) or os.environ.get("UPDATE"): print "generating expected test image: %s" % expected im.save(expected, "png32") expected_im = mapnik.Image.open(expected) # compare them if im.tostring("png32") == expected_im.tostring("png32"): successes.append(name) else: fails.append( "failed comparing actual (%s) and expected(%s)" % (actual, "tests/python_tests/" + expected) ) fail_im = side_by_side_image(expected_im, im) fail_im.save("/tmp/mapnik-style-comp-op-" + name + ".fail.png", "png32") eq_(len(fails), 0, "\n" + "\n".join(fails))
def compare_images(expected, im): if not os.path.exists(expected) or os.environ.get('UPDATE'): print 'generating expected image %s' % expected im.save(expected, 'png32') expected_im = mapnik.Image.open(expected) diff = expected.replace('.png', '-diff.png') if len(im.tostring("png32")) != len(expected_im.tostring("png32")): compared = side_by_side_image(expected_im, im) compared.save(diff) assert False, 'images do not match, check diff at %s' % diff else: if os.path.exists(diff): os.unlink(diff) return True
def compare_images(expected,im): expected = os.path.join(os.path.dirname(expected),os.path.basename(expected).replace(':','_')) if not os.path.exists(expected) or os.environ.get('UPDATE'): print 'generating expected image %s' % expected im.save(expected,'png32') expected_im = mapnik.Image.open(expected) diff = expected.replace('.png','-diff.png') if len(im.tostring("png32")) != len(expected_im.tostring("png32")): compared = side_by_side_image(expected_im, im) compared.save(diff) assert False,'images do not match, check diff at %s' % diff else: if os.path.exists(diff): os.unlink(diff) return True
def test_style_level_image_filter(): m = mapnik.Map(256, 256) mapnik.load_map(m, '../data/good_maps/style_level_image_filter.xml') m.zoom_all() successes = [] fails = [] for name in ("", "agg-stack-blur(2,2)", "blur", "edge-detect", "emboss", "gray", "invert", "sharpen", "sobel", "x-gradient", "y-gradient"): if name == "": filename = "none" else: filename = re.sub(r"[^-_a-z.0-9]", "", name) # find_style returns a copy of the style object style_markers = m.find_style("markers") style_markers.image_filters = name style_labels = m.find_style("labels") style_labels.image_filters = name # replace the original style with the modified one replace_style(m, "markers", style_markers) replace_style(m, "labels", style_labels) im = mapnik.Image(m.width, m.height) mapnik.render(m, im) actual = '/tmp/mapnik-style-image-filter-' + filename + '.png' expected = 'images/style-image-filter/' + filename + '.png' im.save(actual, "png32") if not os.path.exists(expected) or os.environ.get('UPDATE'): print 'generating expected test image: %s' % expected im.save(expected, 'png32') expected_im = mapnik.Image.open(expected) # compare them if im.tostring('png32') == expected_im.tostring('png32'): successes.append(name) else: fails.append('failed comparing actual (%s) and expected(%s)' % (actual, 'tests/python_tests/' + expected)) fail_im = side_by_side_image(expected_im, im) fail_im.save( '/tmp/mapnik-style-image-filter-' + filename + '.fail.png', 'png32') eq_(len(fails), 0, '\n' + '\n'.join(fails))
def test_style_level_image_filter(): m = mapnik.Map(256, 256) mapnik.load_map(m, '../data/good_maps/style_level_image_filter.xml') m.zoom_all() successes = [] fails = [] for name in ("", "agg-stack-blur(2,2)", "blur", "edge-detect", "emboss", "gray", "invert", "sharpen", "sobel", "x-gradient", "y-gradient"): if name == "": filename = "none" else: filename = re.sub(r"[^-_a-z.0-9]", "", name) # find_style returns a copy of the style object style_markers = m.find_style("markers") style_markers.image_filters = name style_labels = m.find_style("labels") style_labels.image_filters = name # replace the original style with the modified one replace_style(m, "markers", style_markers) replace_style(m, "labels", style_labels) im = mapnik.Image(m.width, m.height) mapnik.render(m, im) actual = '/tmp/mapnik-style-image-filter-' + filename + '.png' expected = 'images/style-image-filter/' + filename + '.png' im.save(actual,"png32") if not os.path.exists(expected): print 'generating expected test image: %s' % expected im.save(expected,'png32') expected_im = mapnik.Image.open(expected) # compare them if im.tostring('png32') == expected_im.tostring('png32'): successes.append(name) else: fails.append('failed comparing actual (%s) and expected(%s)' % (actual,'tests/python_tests/'+ expected)) fail_im = side_by_side_image(expected_im, im) fail_im.save('/tmp/mapnik-style-image-filter-' + filename + '.fail.png','png32') eq_(len(fails), 0, '\n'+'\n'.join(fails))