File: load_map_test.py

package info (click to toggle)
mapnik 2.0.0%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 35,496 kB
  • sloc: cpp: 91,793; python: 6,051; xml: 3,528; sh: 848; makefile: 70; lisp: 10
file content (54 lines) | stat: -rw-r--r-- 1,494 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python

from nose.tools import *
from utilities import execution_path

import os, sys, glob, mapnik2

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):
    m = mapnik2.Map(512, 512)

    strict = True
    mapnik2.load_map(m, file, strict)
    
    # 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) + '/'
    mapnik2.load_map_from_string(m,open(file,'rb').read(),strict,base_path)
    

# We expect these files to raise a RuntimeError
# and fail if there isn't one (or a different type
# of exception)
@raises(RuntimeError)
def assert_raises_runtime_error(file):
    m = mapnik2.Map(512, 512)

    strict = True
    mapnik2.load_map(m, file, strict)

def test_broken_files():
    broken_files = glob.glob("../data/broken_maps/*.xml")

    # Add a filename that doesn't exist 
    broken_files.append("../data/broken/does_not_exist.xml")

    for file in broken_files:
        yield assert_raises_runtime_error, file

def test_good_files():
    good_files = glob.glob("../data/good_maps/*.xml")

    for file in good_files:
        yield assert_loads_successfully, file

if __name__ == "__main__":
    setup()
    [eval(run)() for run in dir() if 'test_' in run]