2009-04-15 23:06:18 +00:00
|
|
|
#!/usr/bin/env python
|
2007-09-25 21:06:52 +00:00
|
|
|
|
2015-02-02 18:31:16 +00:00
|
|
|
from nose.tools import eq_
|
2013-05-29 21:11:28 +00:00
|
|
|
from utilities import execution_path, run_all
|
2007-09-25 21:06:52 +00:00
|
|
|
|
2015-02-02 18:31:16 +00:00
|
|
|
import os, glob, mapnik
|
2009-04-12 22:38:46 +00:00
|
|
|
|
2013-11-14 02:45:30 +00:00
|
|
|
default_logging_severity = mapnik.logger.get_severity()
|
|
|
|
|
2009-04-12 22:38:46 +00:00
|
|
|
def setup():
|
2013-11-14 02:45:30 +00: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-12 22:38:46 +00: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 02:45:30 +00:00
|
|
|
def teardown():
|
|
|
|
mapnik.logger.set_severity(default_logging_severity)
|
|
|
|
|
2009-04-12 22:38:46 +00:00
|
|
|
def test_broken_files():
|
2013-06-03 01:40:06 +00:00
|
|
|
default_logging_severity = mapnik.logger.get_severity()
|
|
|
|
mapnik.logger.set_severity(mapnik.severity_type.None)
|
2007-09-25 21:06:52 +00:00
|
|
|
broken_files = glob.glob("../data/broken_maps/*.xml")
|
2009-04-12 22:38:46 +00:00
|
|
|
# Add a filename that doesn't exist
|
|
|
|
broken_files.append("../data/broken/does_not_exist.xml")
|
2007-09-25 21:06:52 +00:00
|
|
|
|
2013-05-29 21:11:28 +00: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 01:40:06 +00:00
|
|
|
mapnik.logger.set_severity(default_logging_severity)
|
2007-09-25 21:06:52 +00:00
|
|
|
|
2015-01-09 18:48:50 +00: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 18:59:18 +00:00
|
|
|
files_with_deprecated_props = glob.glob("../data/deprecated_maps/*.xml")
|
2015-01-09 18:48:50 +00:00
|
|
|
|
|
|
|
failures = [];
|
2015-01-09 18:59:18 +00:00
|
|
|
for filename in files_with_deprecated_props:
|
2015-01-09 18:48:50 +00: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-12 22:38:46 +00:00
|
|
|
def test_good_files():
|
|
|
|
good_files = glob.glob("../data/good_maps/*.xml")
|
2013-09-25 20:08:10 +00:00
|
|
|
good_files.extend(glob.glob("../visual_tests/styles/*.xml"))
|
2007-09-25 21:06:52 +00:00
|
|
|
|
2013-05-29 21:11:28 +00:00
|
|
|
failures = [];
|
|
|
|
for filename in good_files:
|
|
|
|
try:
|
|
|
|
m = mapnik.Map(512, 512)
|
2013-12-03 05:51:24 +00:00
|
|
|
strict = True
|
2013-05-29 21:11:28 +00:00
|
|
|
mapnik.load_map(m, filename, strict)
|
2013-06-02 23:06:32 +00:00
|
|
|
base_path = os.path.dirname(filename)
|
2013-05-29 21:11:28 +00: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 00:36:50 +00:00
|
|
|
if not 'Could not create datasource' in str(e) \
|
|
|
|
and not 'Bad connection' in str(e):
|
2013-12-03 05:51:24 +00:00
|
|
|
failures.append('Failed to load valid map %s (%s)' % (filename,e))
|
2013-05-29 21:11:28 +00:00
|
|
|
eq_(len(failures),0,'\n'+'\n'.join(failures))
|
2011-08-30 22:51:42 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
setup()
|
2014-07-14 16:34:20 +00:00
|
|
|
exit(run_all(eval(x) for x in dir() if x.startswith("test_")))
|