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 *
|
2016-08-02 19:53:24 +02:00
|
|
|
from utilities import execution_path, run_all, datasources_available
|
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
|
|
|
|
2009-04-13 00:38:46 +02:00
|
|
|
def test_good_files():
|
2016-08-02 19:53:24 +02:00
|
|
|
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:
|
2016-08-03 17:11:27 +02:00
|
|
|
print 'Notice: skipping load_map_test for %s due to unavailable input plugins: %s' % (os.path.basename(xmlfile), list(missing_plugins))
|
2007-09-25 23:06:52 +02:00
|
|
|
|
2013-05-29 23:11:28 +02:00
|
|
|
failures = [];
|
2016-08-02 19:53:24 +02:00
|
|
|
strict = False
|
2013-05-29 23:11:28 +02:00
|
|
|
for filename in good_files:
|
|
|
|
try:
|
|
|
|
m = mapnik.Map(512, 512)
|
|
|
|
mapnik.load_map(m, filename, strict)
|
2013-06-03 01:06:32 +02:00
|
|
|
base_path = os.path.dirname(filename)
|
2016-08-02 19:53:24 +02:00
|
|
|
mapnik.load_map_from_string(m, open(filename, 'rb').read(), strict, base_path)
|
2013-05-29 23:11:28 +02:00
|
|
|
except RuntimeError, e:
|
2016-08-02 19:53:24 +02:00
|
|
|
failures.append('Failed to load valid map %s (%s)!' % (filename, str(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_")))
|