File: test_load_map.py

package info (click to toggle)
mapnik 0.5.1-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 19,136 kB
  • ctags: 14,550
  • sloc: cpp: 68,887; python: 24,895; xml: 1,534; makefile: 503; sh: 79
file content (91 lines) | stat: -rwxr-xr-x 2,047 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/python

from mapnik import *
import sys
import glob

def testGood( file ) :
    print "Testing good file '" + file + "' ... ",
    
    m = Map(512, 512)
    try:
        load_map(m, file, True)
    except RuntimeError, what:
        print "FAILED"
        print what
        return False
    except:
        print "FAILED"
        return False
    else:
        print "OK"
        return True


def testBroken( file ) :
    print "Testing broken file '" + file + "' ... ",

    m = Map(512, 512)
    try:
        strict = True
        load_map(m, file, strict)
    except UserWarning, what:
        print "OK"
        print "=== Error Message ============="
        print what
        print 
        return True
    except RuntimeError, what:
        print "FAILED (not a UserWarning)"
        print "=== Error Message ============="
        print what
        print 
    else:
        print "FAILED"

    return False


def test():
    success = 0
    failed = 0
    failed_tests = []

    broken_files = glob.glob("../data/broken_maps/*.xml")
    # eh, can't glob this ... :-)
    broken_files.append( "../data/broken/does_not_exist.xml" ) 
    for file in broken_files:
        if testBroken( file ):
            success += 1
        else:
            failed += 1
            failed_tests.append( file )

    good_files = glob.glob("../data/good_maps/*.xml")
    for file in good_files:
        if testGood( file ):
            success += 1
        else:
            failed += 1
            failed_tests.append( file )

    print "======================================================="
    print "Status:",
    if failed:
        print "FAILED"
        print "Errors in: ", failed_tests
    else:
        print "SUCCESS"
    print "Success:", success, "Failed:", failed, "Total:", success + failed
    print "======================================================="
    if failed:
        return False
    else:
        return True


if __name__ == "__main__":
    if test():
        sys.exit( 0 )
    else:
        sys.exit( 1 )