2009-04-15 23:06:18 +00:00
|
|
|
#!/usr/bin/env python
|
2007-09-25 21:06:52 +00:00
|
|
|
|
2009-04-12 22:38:46 +00:00
|
|
|
from nose.tools import *
|
|
|
|
from utilities import execution_path
|
2007-09-25 21:06:52 +00:00
|
|
|
|
2011-11-23 11:33:58 +00:00
|
|
|
import os, sys, glob, mapnik
|
2009-04-12 22:38:46 +00: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('.'))
|
|
|
|
|
|
|
|
# We expect these files to not raise any
|
|
|
|
# exceptions at all
|
|
|
|
def assert_loads_successfully(file):
|
2011-11-23 11:33:58 +00:00
|
|
|
m = mapnik.Map(512, 512)
|
2007-09-25 21:06:52 +00:00
|
|
|
|
2011-10-29 00:06:23 +00:00
|
|
|
try:
|
|
|
|
strict = True
|
2011-11-23 11:33:58 +00:00
|
|
|
mapnik.load_map(m, file, strict)
|
2012-02-24 21:13:56 +00:00
|
|
|
|
2011-10-29 00:06:23 +00:00
|
|
|
# libxml2 is not smart about paths, and clips the last directory off
|
|
|
|
# of a path if it does not end in a trailing slash
|
|
|
|
base_path = os.path.dirname(file) + '/'
|
2011-11-23 11:33:58 +00:00
|
|
|
mapnik.load_map_from_string(m,open(file,'rb').read(),strict,base_path)
|
2011-10-29 00:06:23 +00:00
|
|
|
except RuntimeError, e:
|
|
|
|
# only test datasources that we have installed
|
|
|
|
if not 'Could not create datasource' in str(e):
|
|
|
|
raise RuntimeError(e)
|
2012-02-24 21:13:56 +00:00
|
|
|
|
2007-09-25 21:06:52 +00:00
|
|
|
|
2009-12-07 00:04:59 +00:00
|
|
|
# We expect these files to raise a RuntimeError
|
2009-04-12 22:38:46 +00:00
|
|
|
# and fail if there isn't one (or a different type
|
|
|
|
# of exception)
|
2009-12-07 00:04:59 +00:00
|
|
|
@raises(RuntimeError)
|
|
|
|
def assert_raises_runtime_error(file):
|
2011-11-23 11:33:58 +00:00
|
|
|
m = mapnik.Map(512, 512)
|
2007-09-25 21:06:52 +00:00
|
|
|
|
2009-04-12 22:38:46 +00:00
|
|
|
strict = True
|
2011-11-23 11:33:58 +00:00
|
|
|
mapnik.load_map(m, file, strict)
|
2007-09-25 21:06:52 +00:00
|
|
|
|
2009-04-12 22:38:46 +00:00
|
|
|
def test_broken_files():
|
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
|
|
|
|
2009-04-12 22:38:46 +00:00
|
|
|
for file in broken_files:
|
2009-12-07 00:04:59 +00:00
|
|
|
yield assert_raises_runtime_error, file
|
2007-09-25 21:06:52 +00:00
|
|
|
|
2009-04-12 22:38:46 +00:00
|
|
|
def test_good_files():
|
|
|
|
good_files = glob.glob("../data/good_maps/*.xml")
|
2007-09-25 21:06:52 +00:00
|
|
|
|
2009-04-12 22:38:46 +00:00
|
|
|
for file in good_files:
|
|
|
|
yield assert_loads_successfully, file
|
2011-08-30 22:51:42 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
setup()
|
|
|
|
[eval(run)() for run in dir() if 'test_' in run]
|