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