tweak a few tests to only run if shape.input is available

This commit is contained in:
Dane Springmeyer 2012-10-29 11:19:17 -07:00
parent ae156671be
commit a62e791d73
3 changed files with 107 additions and 109 deletions

View file

@ -149,47 +149,48 @@ def test_pre_multiply_status_of_map2():
mapnik.render(m,im)
eq_(validate_pixels_are_not_premultiplied(im),True)
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))
if 'shape' in mapnik.DatasourceCache.plugin_names():
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_style_level_opacity():
m = mapnik.Map(512,512)
mapnik.load_map(m,'../data/good_maps/style_level_opacity_and_blur.xml')
m.zoom_all()
im = mapnik.Image(512,512)
mapnik.render(m,im)
actual = '/tmp/mapnik-style-level-opacity.png'
expected = 'images/support/mapnik-style-level-opacity.png'
im.save(actual)
expected_im = mapnik.Image.open(expected)
eq_(im.tostring(),expected_im.tostring(), 'failed comparing actual (%s) and expected (%s)' % (actual,'tests/python_tests/'+ expected))
def test_style_level_opacity():
m = mapnik.Map(512,512)
mapnik.load_map(m,'../data/good_maps/style_level_opacity_and_blur.xml')
m.zoom_all()
im = mapnik.Image(512,512)
mapnik.render(m,im)
actual = '/tmp/mapnik-style-level-opacity.png'
expected = 'images/support/mapnik-style-level-opacity.png'
im.save(actual)
expected_im = mapnik.Image.open(expected)
eq_(im.tostring(),expected_im.tostring(), 'failed comparing actual (%s) and expected (%s)' % (actual,'tests/python_tests/'+ expected))
def test_rounding_and_color_expectations():
m = mapnik.Map(1,1)

View file

@ -23,44 +23,45 @@ def test_append():
s.image_filters = 'sharpen'
eq_(s.image_filters,'sharpen')
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)
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-image-filter-' + filename + '.fail.png')
eq_(len(fails), 0, '\n'+'\n'.join(fails))
if 'shape' in mapnik.DatasourceCache.plugin_names():
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)
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-image-filter-' + filename + '.fail.png')
eq_(len(fails), 0, '\n'+'\n'.join(fails))
if __name__ == "__main__":
setup()

View file

@ -10,34 +10,30 @@ def setup():
# from another directory we need to chdir()
os.chdir(execution_path('.'))
def test_query_tolerance():
srs = '+init=epsg:4326'
lyr = mapnik.Layer('test')
lyr.datasource = mapnik.Shapefile(file='../data/shp/arrows.shp')
lyr.srs = srs
_width = 256
_map = mapnik.Map(_width,_width, srs)
_map.layers.append(lyr)
# zoom determines tolerance
_map.zoom_all()
_map_env = _map.envelope()
tol = (_map_env.maxx - _map_env.minx) / _width * 3
# 0.046875 for arrows.shp and zoom_all
assert tol == 0.046875
# check point really exists
x, y = 2.0, 4.0
features = _map.query_point(0,x,y).features
assert len(features) == 1
# check inside tolerance limit
x = 2.0 + tol * 0.9
features = _map.query_point(0,x,y).features
assert len(features) == 1
# check outside tolerance limit
x = 2.0 + tol * 1.1
features = _map.query_point(0,x,y).features
assert len(features) == 0
if 'shape' in mapnik.DatasourceCache.plugin_names():
def test_query_tolerance():
srs = '+init=epsg:4326'
lyr = mapnik.Layer('test')
lyr.datasource = mapnik.Shapefile(file='../data/shp/arrows.shp')
lyr.srs = srs
_width = 256
_map = mapnik.Map(_width,_width, srs)
_map.layers.append(lyr)
# zoom determines tolerance
_map.zoom_all()
_map_env = _map.envelope()
tol = (_map_env.maxx - _map_env.minx) / _width * 3
# 0.046875 for arrows.shp and zoom_all
assert tol == 0.046875
# check point really exists
x, y = 2.0, 4.0
features = _map.query_point(0,x,y).features
assert len(features) == 1
# check inside tolerance limit
x = 2.0 + tol * 0.9
features = _map.query_point(0,x,y).features
assert len(features) == 1
# check outside tolerance limit
x = 2.0 + tol * 1.1
features = _map.query_point(0,x,y).features
assert len(features) == 0