Skip to content

Fix the way test cases handle unavailable input plugins #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions test/python_tests/datasource_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import mapnik

from .utilities import execution_path, run_all
from .utilities import execution_path, run_all, datasources_available

PYTHON3 = sys.version_info[0] == 3
if PYTHON3:
Expand Down Expand Up @@ -164,9 +164,10 @@ def rle_encode(l):
return ["%d:%s" % (len(list(group)), name)
for name, group in groupby(l)]

m = mapnik.Map(256, 256)
try:
mapnik.load_map(m, '../data/good_maps/agg_poly_gamma_map.xml')
xmlfile = '../data/good_maps/agg_poly_gamma_map.xml'
if datasources_available(xmlfile):
m = mapnik.Map(256, 256)
mapnik.load_map(m, xmlfile)
m.zoom_all()
join_field = 'NAME'
fg = [] # feature grid
Expand All @@ -182,10 +183,6 @@ def rle_encode(l):
hit_list = '|'.join(rle_encode(fg))
eq_(hit_list[:16], '730:|2:Greenland')
eq_(hit_list[-12:], '1:Chile|812:')
except RuntimeError as e:
# only test datasources that we have installed
if not 'Could not create datasource' in str(e):
raise RuntimeError(str(e))


if __name__ == '__main__':
Expand Down
9 changes: 3 additions & 6 deletions test/python_tests/layer_modification_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def test_adding_datasource_to_layer():

</Map>
'''
m = mapnik.Map(256, 256)
if 'shape' in mapnik.DatasourceCache.plugin_names():
m = mapnik.Map(256, 256)

try:
mapnik.load_map_from_string(m, map_string)

# validate it loaded fine
Expand Down Expand Up @@ -73,10 +73,7 @@ def test_adding_datasource_to_layer():
eq_(m.layers[
0].srs, '+proj=merc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs')
eq_(lyr.srs, '+proj=merc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs')
except RuntimeError as e:
# only test datasources that we have installed
if not 'Could not create datasource' in str(e):
raise RuntimeError(e)


if __name__ == "__main__":
setup()
Expand Down
58 changes: 32 additions & 26 deletions test/python_tests/load_map_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import mapnik

from .utilities import execution_path, run_all
from .utilities import execution_path, run_all, datasources_available


default_logging_severity = mapnik.logger.get_severity()
Expand Down Expand Up @@ -55,46 +55,52 @@ def test_can_parse_xml_with_deprecated_properties():

failures = []
for filename in files_with_deprecated_props:
try:
m = mapnik.Map(512, 512)
strict = True
mapnik.load_map(m, filename, strict)
base_path = os.path.dirname(filename)
mapnik.load_map_from_string(
m,
open(
filename,
'rb').read(),
strict,
base_path)
except RuntimeError as e:
# only test datasources that we have installed
if not 'Could not create datasource' in str(e) \
and not 'could not connect' in str(e):
failures.append(
'Failed to load valid map %s (%s)' %
(filename, e))
if datasources_available(filename):
try:
m = mapnik.Map(512, 512)
strict = True
mapnik.load_map(m, filename, strict)
base_path = os.path.dirname(filename)
mapnik.load_map_from_string(
m,
open(
filename,
'rb').read(),
strict,
base_path)
except RuntimeError as e:
if not 'could not connect' in str(e):
failures.append(
'Failed to load valid map %s (%s)' %
(filename, e))
eq_(len(failures), 0, '\n' + '\n'.join(failures))
mapnik.logger.set_severity(default_logging_severity)


def test_good_files():
good_files = glob.glob("../data/good_maps/*.xml")
good_files.extend(glob.glob("../visual_tests/styles/*.xml"))
all_files = glob.glob("../data/good_maps/*.xml")
all_files.extend(glob.glob("../visual_tests/styles/*.xml"))

good_files = list()
for xmlfile in all_files:
missing_plugins = set()
have_inputs = datasources_available(xmlfile, missing_plugins)
if have_inputs:
good_files.append(xmlfile)
else:
print 'Notice: skipping load_map_test for %s due to unavailable input plugins: %s' % (os.path.basename(xmlfile), list(missing_plugins))

failures = []
strict = True
for filename in good_files:
try:
m = mapnik.Map(512, 512)
strict = True
mapnik.load_map(m, filename, strict)
base_path = os.path.dirname(filename)
with open(filename, 'rb') as f:
mapnik.load_map_from_string(m, f.read(), strict, base_path)
except RuntimeError as e:
# only test datasources that we have installed
if not 'Could not create datasource' in str(e) \
and not 'could not connect' in str(e):
if not 'could not connect' in str(e):
failures.append(
'Failed to load valid map %s (%s)' %
(filename, e))
Expand Down
10 changes: 3 additions & 7 deletions test/python_tests/object_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@
# </Layer>
# </Map>'''

# m = mapnik.Map(600, 300)
# eq_(m.base, '')
# try:
# if 'shape' in mapnik.DatasourceCache.plugin_names():
# m = mapnik.Map(600, 300)
# eq_(m.base, '')
# mapnik.load_map_from_string(m, map_string)
# eq_(m.base, './')
# mapnik.load_map_from_string(m, map_string, False, "") # this "" will have no effect
Expand All @@ -394,10 +394,6 @@
# m.base = 'foo'
# mapnik.load_map_from_string(m, map_string, True, ".")
# eq_(m.base, '.')
# except RuntimeError, e:
# # only test datasources that we have installed
# if not 'Could not create datasource' in str(e):
# raise RuntimeError(e)

# # Color initialization
# @raises(Exception) # Boost.Python.ArgumentError
Expand Down
27 changes: 11 additions & 16 deletions test/python_tests/raster_symbolizer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import mapnik

from .utilities import execution_path, get_unique_colors, run_all
from .utilities import execution_path, get_unique_colors, run_all, datasources_available


def setup():
Expand Down Expand Up @@ -106,28 +106,23 @@ def test_dataraster_query_point():


def test_load_save_map():
map = mapnik.Map(256, 256)
m = mapnik.Map(256, 256)
in_map = "../data/good_maps/raster_symbolizer.xml"
try:
mapnik.load_map(map, in_map)

out_map = mapnik.save_map_to_string(map)
if datasources_available(in_map):
mapnik.load_map(m, in_map)
out_map = mapnik.save_map_to_string(m)
assert 'RasterSymbolizer' in out_map
assert 'RasterColorizer' in out_map
assert 'stop' in out_map
except RuntimeError as e:
# only test datasources that we have installed
if not 'Could not create datasource' in str(e):
raise RuntimeError(str(e))


def test_raster_with_alpha_blends_correctly_with_background():
WIDTH = 500
HEIGHT = 500

map = mapnik.Map(WIDTH, HEIGHT)
m = mapnik.Map(WIDTH, HEIGHT)
WHITE = mapnik.Color(255, 255, 255)
map.background = WHITE
m.background = WHITE

style = mapnik.Style()
rule = mapnik.Rule()
Expand All @@ -137,20 +132,20 @@ def test_raster_with_alpha_blends_correctly_with_background():
rule.symbols.append(symbolizer)
style.rules.append(rule)

map.append_style('raster_style', style)
m.append_style('raster_style', style)

map_layer = mapnik.Layer('test_layer')
filepath = '../data/raster/white-alpha.png'
if 'gdal' in mapnik.DatasourceCache.plugin_names():
map_layer.datasource = mapnik.Gdal(file=filepath)
map_layer.styles.append('raster_style')
map.layers.append(map_layer)
m.layers.append(map_layer)

map.zoom_all()
m.zoom_all()

mim = mapnik.Image(WIDTH, HEIGHT)

mapnik.render(map, mim)
mapnik.render(m, mim)
mim.tostring()
# All white is expected
eq_(get_unique_colors(mim), ['rgba(254,254,254,255)'])
Expand Down
17 changes: 7 additions & 10 deletions test/python_tests/render_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import mapnik

from .utilities import execution_path, run_all
from .utilities import execution_path, run_all, datasources_available

PYTHON3 = sys.version_info[0] == 3

Expand Down Expand Up @@ -126,18 +126,15 @@ def get_paired_images(w, h, mapfile):


def test_render_from_serialization():
try:
im, im2 = get_paired_images(
100, 100, '../data/good_maps/building_symbolizer.xml')
xmlfile = '../data/good_maps/building_symbolizer.xml'
if datasources_available(xmlfile):
im, im2 = get_paired_images(100, 100, xmlfile)
eq_(im.tostring('png32'), im2.tostring('png32'))

im, im2 = get_paired_images(
100, 100, '../data/good_maps/polygon_symbolizer.xml')
xmlfile = '../data/good_maps/polygon_symbolizer.xml'
if datasources_available(xmlfile):
im, im2 = get_paired_images(100, 100, xmlfile)
eq_(im.tostring('png32'), im2.tostring('png32'))
except RuntimeError as e:
# only test datasources that we have installed
if not 'Could not create datasource' in str(e):
raise RuntimeError(e)


def test_render_points():
Expand Down
26 changes: 11 additions & 15 deletions test/python_tests/save_map_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import mapnik

from .utilities import execution_path, run_all
from .utilities import execution_path, run_all, datasources_available


default_logging_severity = mapnik.logger.get_severity()
Expand All @@ -27,17 +27,16 @@ def teardown():
mapnik.logger.set_severity(default_logging_severity)


def compare_map(xml):
def compare_map(xmlfile):
missing_plugins = set()
have_inputs = datasources_available(xmlfile, missing_plugins)
if not have_inputs:
print 'Notice: skipping saved map comparison for %s due to unavailable input plugins: %s' % (os.path.basename(xmlfile), list(missing_plugins))
return False

m = mapnik.Map(256, 256)
absolute_base = os.path.abspath(os.path.dirname(xml))
try:
mapnik.load_map(m, xml, False, absolute_base)
except RuntimeError as e:
# only test datasources that we have installed
if not 'Could not create datasource' in str(e) \
and not 'could not connect' in str(e):
raise RuntimeError(str(e))
return
absolute_base = os.path.abspath(os.path.dirname(xmlfile))
mapnik.load_map(m, xmlfile, False, absolute_base)
(handle, test_map) = tempfile.mkstemp(
suffix='.xml', prefix='mapnik-temp-map1-')
os.close(handle)
Expand All @@ -60,7 +59,7 @@ def compare_map(xml):
except AssertionError as e:
raise AssertionError(
'serialized map "%s" not the same after being reloaded, \ncompare with command:\n\n$%s' %
(xml, diff))
(xmlfile, diff))

if os.path.exists(test_map):
os.remove(test_map)
Expand All @@ -72,9 +71,6 @@ def compare_map(xml):
def test_compare_map():
good_maps = glob.glob("../data/good_maps/*.xml")
good_maps = [os.path.normpath(p) for p in good_maps]
# remove one map that round trips CDATA differently, but this is okay
ignorable = os.path.join('..', 'data', 'good_maps', 'empty_parameter2.xml')
good_maps.remove(ignorable)
for m in good_maps:
compare_map(m)

Expand Down
Loading