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
|
|
|
|
|
|
|
def setup():
|
|
|
|
# All of the paths used are relative, if we run the tests
|
|
|
|
# from another directory we need to chdir()
|
|
|
|
os.chdir(execution_path('.'))
|
|
|
|
|
|
|
|
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():
|
|
|
|
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-10-24 08:59:14 +02:00
|
|
|
strict = False
|
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
|
|
|
|
if not 'Could not create datasource' in str(e):
|
|
|
|
failures.append('Failed to load valid map (%s)!' % filename)
|
|
|
|
eq_(len(failures),0,'\n'+'\n'.join(failures))
|
2011-08-31 00:51:42 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
setup()
|
2013-05-29 23:11:28 +02:00
|
|
|
run_all(eval(x) for x in dir() if x.startswith("test_"))
|