2009-04-16 01:06:18 +02:00
|
|
|
#!/usr/bin/env python
|
2007-09-25 23:06:52 +02:00
|
|
|
|
2009-04-13 00:38:46 +02:00
|
|
|
from nose.tools import *
|
2013-05-29 23:11:28 +02:00
|
|
|
from utilities import execution_path, run_all
|
2007-09-25 23:06:52 +02:00
|
|
|
|
2011-11-23 12:33:58 +01:00
|
|
|
import os, sys, glob, mapnik
|
2009-04-13 00:38:46 +02:00
|
|
|
|
2013-11-14 03:45:30 +01:00
|
|
|
default_logging_severity = mapnik.logger.get_severity()
|
|
|
|
|
2009-04-13 00:38:46 +02:00
|
|
|
def setup():
|
2013-11-14 03:45:30 +01:00
|
|
|
# make the tests silent to suppress unsupported params from harfbuzz tests
|
|
|
|
# TODO: remove this after harfbuzz branch merges
|
|
|
|
mapnik.logger.set_severity(mapnik.severity_type.None)
|
2009-04-13 00:38:46 +02:00
|
|
|
# All of the paths used are relative, if we run the tests
|
|
|
|
# from another directory we need to chdir()
|
|
|
|
os.chdir(execution_path('.'))
|
|
|
|
|
2013-11-14 03:45:30 +01:00
|
|
|
def teardown():
|
|
|
|
mapnik.logger.set_severity(default_logging_severity)
|
|
|
|
|
2009-04-13 00:38:46 +02:00
|
|
|
def test_broken_files():
|
2013-06-03 03:40:06 +02:00
|
|
|
default_logging_severity = mapnik.logger.get_severity()
|
|
|
|
mapnik.logger.set_severity(mapnik.severity_type.None)
|
2007-09-25 23:06:52 +02:00
|
|
|
broken_files = glob.glob("../data/broken_maps/*.xml")
|
2009-04-13 00:38:46 +02:00
|
|
|
# Add a filename that doesn't exist
|
|
|
|
broken_files.append("../data/broken/does_not_exist.xml")
|
2007-09-25 23:06:52 +02:00
|
|
|
|
2013-05-29 23:11:28 +02:00
|
|
|
failures = [];
|
|
|
|
for filename in broken_files:
|
|
|
|
try:
|
|
|
|
m = mapnik.Map(512, 512)
|
|
|
|
strict = True
|
|
|
|
mapnik.load_map(m, filename, strict)
|
|
|
|
failures.append('Loading broken map (%s) did not raise RuntimeError!' % filename)
|
|
|
|
except RuntimeError:
|
|
|
|
pass
|
|
|
|
eq_(len(failures),0,'\n'+'\n'.join(failures))
|
2013-06-03 03:40:06 +02:00
|
|
|
mapnik.logger.set_severity(default_logging_severity)
|
2007-09-25 23:06:52 +02:00
|
|
|
|
2015-01-09 19:48:50 +01:00
|
|
|
def test_can_parse_xml_with_deprecated_properties():
|
|
|
|
default_logging_severity = mapnik.logger.get_severity()
|
|
|
|
mapnik.logger.set_severity(mapnik.severity_type.None)
|
2015-01-09 19:59:18 +01:00
|
|
|
files_with_deprecated_props = glob.glob("../data/deprecated_maps/*.xml")
|
2015-01-09 19:48:50 +01:00
|
|
|
|
|
|
|
failures = [];
|
2015-01-09 19:59:18 +01:00
|
|
|
for filename in files_with_deprecated_props:
|
2015-01-09 19:48:50 +01:00
|
|
|
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, e:
|
|
|
|
# only test datasources that we have installed
|
|
|
|
if not 'Could not create datasource' in str(e) \
|
|
|
|
and not 'Bad connection' 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)
|
|
|
|
|
2009-04-13 00:38:46 +02:00
|
|
|
def test_good_files():
|
|
|
|
good_files = glob.glob("../data/good_maps/*.xml")
|
2013-09-25 22:08:10 +02:00
|
|
|
good_files.extend(glob.glob("../visual_tests/styles/*.xml"))
|
2007-09-25 23:06:52 +02:00
|
|
|
|
2013-05-29 23:11:28 +02:00
|
|
|
failures = [];
|
|
|
|
for filename in good_files:
|
|
|
|
try:
|
|
|
|
m = mapnik.Map(512, 512)
|
2013-12-03 06:51:24 +01:00
|
|
|
strict = True
|
2013-05-29 23:11:28 +02:00
|
|
|
mapnik.load_map(m, filename, strict)
|
2013-06-03 01:06:32 +02:00
|
|
|
base_path = os.path.dirname(filename)
|
2013-05-29 23:11:28 +02:00
|
|
|
mapnik.load_map_from_string(m,open(filename,'rb').read(),strict,base_path)
|
|
|
|
except RuntimeError, e:
|
|
|
|
# only test datasources that we have installed
|
2014-09-25 02:36:50 +02:00
|
|
|
if not 'Could not create datasource' in str(e) \
|
|
|
|
and not 'Bad connection' in str(e):
|
2013-12-03 06:51:24 +01:00
|
|
|
failures.append('Failed to load valid map %s (%s)' % (filename,e))
|
2013-05-29 23:11:28 +02:00
|
|
|
eq_(len(failures),0,'\n'+'\n'.join(failures))
|
2011-08-31 00:51:42 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
setup()
|
2014-07-14 18:34:20 +02:00
|
|
|
exit(run_all(eval(x) for x in dir() if x.startswith("test_")))
|