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
|
|
|
|
2010-03-11 18:12:22 +00:00
|
|
|
import os, sys, glob, mapnik2
|
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):
|
2010-03-11 18:12:22 +00:00
|
|
|
m = mapnik2.Map(512, 512)
|
2007-09-25 21:06:52 +00:00
|
|
|
|
2009-04-12 22:38:46 +00:00
|
|
|
strict = True
|
2010-03-11 18:12:22 +00:00
|
|
|
mapnik2.load_map(m, file, strict)
|
2009-12-06 22:18:45 +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) + '/'
|
2010-03-11 18:12:22 +00:00
|
|
|
mapnik2.load_map_from_string(m,open(file,'rb').read(),strict,base_path)
|
2009-12-06 22:18:45 +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):
|
2010-03-11 18:12:22 +00:00
|
|
|
m = mapnik2.Map(512, 512)
|
2007-09-25 21:06:52 +00:00
|
|
|
|
2009-04-12 22:38:46 +00:00
|
|
|
strict = True
|
2010-03-11 18:12:22 +00:00
|
|
|
mapnik2.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
|