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
|
#!/usr/bin/python
from mapnik import *
import os
import sys
import glob
def test():
# success = 0
# failed = 0
# failed_tests = []
# TODO: write a better test
# 1. construct map in memory
# 2. save map as XML
# 3. load map to a second object
# 4. Compare both map objects
map = Map(256, 256)
in_map = "../data/good_maps/osm-styles.xml"
print "Loading map '" + in_map + "' ... ",
load_map( map, in_map )
print "OK"
test_map = "test_map.xml"
failed = False;
try:
print "Saving map '" + test_map + "' ... ",
save_map( map, test_map)
print "OK"
except:
print "FAILED"
failed = True;
if not failed:
new_map = Map(256, 256)
try:
print "Reloading map '" + test_map + "' ... ",
load_map( new_map, test_map)
print "OK"
except UserWarning, what:
print "FAILED"
print "Error: ", what
failed = True;
except RuntimeError, what:
print "FAILED"
print "Error: ", what
failed = True;
except:
print "FAILED"
failed = True;
if not failed and os.path.exists( test_map ):
print "Removing '" + test_map + "'"
os.remove( test_map )
print "======================================================="
print "Status:",
if failed:
print "FAILED"
else:
print "SUCCESS"
print "======================================================="
return not failed
if __name__ == "__main__":
if test():
sys.exit( 0 )
else:
sys.exit( 1 )
|