support running tests without any plugins built

This commit is contained in:
Dane Springmeyer 2013-05-21 20:27:00 -07:00
parent ce34be6aab
commit 1e6e587d60
4 changed files with 60 additions and 49 deletions

View file

@ -9,23 +9,25 @@ def setup():
# from another directory we need to chdir()
os.chdir(execution_path('.'))
# the negative buffer on the layer should
# override the postive map buffer leading
# only one point to be rendered in the map
def test_layer_buffer_size_1():
m = mapnik.Map(512,512)
eq_(m.buffer_size,0)
mapnik.load_map(m,'../data/good_maps/layer_buffer_size_reduction.xml')
eq_(m.buffer_size,256)
eq_(m.layers[0].buffer_size,-150)
m.zoom_all()
im = mapnik.Image(m.width,m.height)
mapnik.render(m,im)
actual = '/tmp/mapnik-layer-buffer-size.png'
expected = 'images/support/mapnik-layer-buffer-size.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))
if 'sqlite' in mapnik.DatasourceCache.plugin_names():
# the negative buffer on the layer should
# override the postive map buffer leading
# only one point to be rendered in the map
def test_layer_buffer_size_1():
m = mapnik.Map(512,512)
eq_(m.buffer_size,0)
mapnik.load_map(m,'../data/good_maps/layer_buffer_size_reduction.xml')
eq_(m.buffer_size,256)
eq_(m.layers[0].buffer_size,-150)
m.zoom_all()
im = mapnik.Image(m.width,m.height)
mapnik.render(m,im)
actual = '/tmp/mapnik-layer-buffer-size.png'
expected = 'images/support/mapnik-layer-buffer-size.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))
if __name__ == "__main__":

View file

@ -27,22 +27,24 @@ def test_reading_palettes():
palette = mapnik.Palette('\xff\x00\xff\xff\xff\xff', 'rgb')
eq_(palette.to_string(),expected_rgb);
def test_render_with_palette():
m = mapnik.Map(600,400)
mapnik.load_map(m,'../data/good_maps/agg_poly_gamma_map.xml')
m.zoom_all()
im = mapnik.Image(m.width,m.height)
mapnik.render(m,im)
act = open('../data/palettes/palette256.act','rb')
palette = mapnik.Palette(act.read(),'act')
# test saving directly to filesystem
im.save('/tmp/mapnik-palette-test.png','png',palette)
# test saving to a string
open('/tmp/mapnik-palette-test2.png','wb').write(im.tostring('png',palette));
# compare the two methods
eq_(mapnik.Image.open('/tmp/mapnik-palette-test.png').tostring(),mapnik.Image.open('/tmp/mapnik-palette-test2.png').tostring(),'%s not eq to %s' % ('/tmp/mapnik-palette-test.png','/tmp/mapnik-palette-test2.png'))
# compare to expected
eq_(mapnik.Image.open('/tmp/mapnik-palette-test.png').tostring(),mapnik.Image.open('./images/support/mapnik-palette-test.png').tostring(),'%s not eq to %s' % ('/tmp/mapnik-palette-test.png','./images/support/mapnik-palette-test.png'))
if 'shape' in mapnik.DatasourceCache.plugin_names():
def test_render_with_palette():
m = mapnik.Map(600,400)
mapnik.load_map(m,'../data/good_maps/agg_poly_gamma_map.xml')
m.zoom_all()
im = mapnik.Image(m.width,m.height)
mapnik.render(m,im)
act = open('../data/palettes/palette256.act','rb')
palette = mapnik.Palette(act.read(),'act')
# test saving directly to filesystem
im.save('/tmp/mapnik-palette-test.png','png',palette)
# test saving to a string
open('/tmp/mapnik-palette-test2.png','wb').write(im.tostring('png',palette));
# compare the two methods
eq_(mapnik.Image.open('/tmp/mapnik-palette-test.png').tostring(),mapnik.Image.open('/tmp/mapnik-palette-test2.png').tostring(),'%s not eq to %s' % ('/tmp/mapnik-palette-test.png','/tmp/mapnik-palette-test2.png'))
# compare to expected
eq_(mapnik.Image.open('/tmp/mapnik-palette-test.png').tostring(),mapnik.Image.open('./images/support/mapnik-palette-test.png').tostring(),'%s not eq to %s' % ('/tmp/mapnik-palette-test.png','./images/support/mapnik-palette-test.png'))
if __name__ == "__main__":
setup()

View file

@ -173,22 +173,24 @@ def test_render_with_scale_factor_zero_throws():
im = mapnik.Image(256, 256)
mapnik.render(m,im,0.0)
def test_render_with_scale_factor():
m = mapnik.Map(256,256)
mapnik.load_map(m,'../data/good_maps/marker-text-line.xml')
m.zoom_all()
sizes = [.00001,.005,.1,.899,1,1.5,2,5,10,100]
for size in sizes:
im = mapnik.Image(256, 256)
mapnik.render(m,im,size)
expected_file = './images/support/marker-text-line-scale-factor-%s.png' % size
actual_file = '/tmp/' + os.path.basename(expected_file)
im.save(actual_file,'png8')
#im.save(expected_file,'png8')
# we save and re-open here so both png8 images are ready as full color png
actual = mapnik.Image.open(expected_file)
expected = mapnik.Image.open(expected_file)
eq_(actual.tostring(),expected.tostring(), 'failed comparing actual (%s) and expected (%s)' % (actual_file,expected_file))
if 'shape' in mapnik.DatasourceCache.plugin_names():
def test_render_with_scale_factor():
m = mapnik.Map(256,256)
mapnik.load_map(m,'../data/good_maps/marker-text-line.xml')
m.zoom_all()
sizes = [.00001,.005,.1,.899,1,1.5,2,5,10,100]
for size in sizes:
im = mapnik.Image(256, 256)
mapnik.render(m,im,size)
expected_file = './images/support/marker-text-line-scale-factor-%s.png' % size
actual_file = '/tmp/' + os.path.basename(expected_file)
im.save(actual_file,'png8')
#im.save(expected_file,'png8')
# we save and re-open here so both png8 images are ready as full color png
actual = mapnik.Image.open(expected_file)
expected = mapnik.Image.open(expected_file)
eq_(actual.tostring(),expected.tostring(), 'failed comparing actual (%s) and expected (%s)' % (actual_file,expected_file))
if __name__ == "__main__":
setup()

View file

@ -174,6 +174,9 @@ class Reporting:
return item
def summary(self):
if self.passed == 0:
print '\nNOTICE: No valid visual tests were run'
return 0
if len(self.errors) == 0:
print '\nAll %s visual tests passed: \x1b[1;32m✓ \x1b[0m' % self.passed
return 0
@ -265,6 +268,8 @@ def render(filename,config, width, height, bbox, scale_factor, reporting):
else:
m.zoom_all()
except Exception, e:
if 'Could not create datasource' in str(e):
return m
reporting.other_error(filename, repr(e))
return m