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 *
|
|
|
|
from utilities import execution_path
|
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('.'))
|
|
|
|
|
|
|
|
# We expect these files to not raise any
|
|
|
|
# exceptions at all
|
|
|
|
def assert_loads_successfully(file):
|
2011-11-23 12:33:58 +01:00
|
|
|
m = mapnik.Map(512, 512)
|
2007-09-25 23:06:52 +02:00
|
|
|
|
2011-10-29 02:06:23 +02:00
|
|
|
try:
|
|
|
|
strict = True
|
2011-11-23 12:33:58 +01:00
|
|
|
mapnik.load_map(m, file, strict)
|
2012-02-24 22:13:56 +01:00
|
|
|
|
2011-10-29 02:06:23 +02: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 12:33:58 +01:00
|
|
|
mapnik.load_map_from_string(m,open(file,'rb').read(),strict,base_path)
|
2011-10-29 02:06:23 +02: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 22:13:56 +01:00
|
|
|
|
2007-09-25 23:06:52 +02:00
|
|
|
|
2009-12-07 01:04:59 +01:00
|
|
|
# We expect these files to raise a RuntimeError
|
2009-04-13 00:38:46 +02:00
|
|
|
# and fail if there isn't one (or a different type
|
|
|
|
# of exception)
|
2009-12-07 01:04:59 +01:00
|
|
|
@raises(RuntimeError)
|
|
|
|
def assert_raises_runtime_error(file):
|
2011-11-23 12:33:58 +01:00
|
|
|
m = mapnik.Map(512, 512)
|
2007-09-25 23:06:52 +02:00
|
|
|
|
2009-04-13 00:38:46 +02:00
|
|
|
strict = True
|
2011-11-23 12:33:58 +01:00
|
|
|
mapnik.load_map(m, file, strict)
|
2007-09-25 23:06:52 +02:00
|
|
|
|
2009-04-13 00:38:46 +02:00
|
|
|
def test_broken_files():
|
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
|
|
|
|
2009-04-13 00:38:46 +02:00
|
|
|
for file in broken_files:
|
2009-12-07 01:04:59 +01:00
|
|
|
yield assert_raises_runtime_error, file
|
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")
|
2007-09-25 23:06:52 +02:00
|
|
|
|
2009-04-13 00:38:46 +02:00
|
|
|
for file in good_files:
|
|
|
|
yield assert_loads_successfully, file
|
2011-08-31 00:51:42 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
setup()
|
|
|
|
[eval(run)() for run in dir() if 'test_' in run]
|