+ switch to nose as testing framework - thanks to Beau for patch and motivation (see #300)
This commit is contained in:
parent
52166debe6
commit
b38634429c
3 changed files with 65 additions and 137 deletions
|
@ -1,91 +1,49 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
from mapnik import *
|
||||
import sys
|
||||
import glob
|
||||
from nose.tools import *
|
||||
from mapnik import Map, load_map
|
||||
from utilities import execution_path
|
||||
|
||||
def testGood( file ) :
|
||||
print "Testing good file '" + file + "' ... ",
|
||||
|
||||
import os, sys, glob
|
||||
|
||||
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 = 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
|
||||
|
||||
print "Loading %s" % (file)
|
||||
|
||||
def testBroken( file ) :
|
||||
print "Testing broken file '" + file + "' ... ",
|
||||
strict = True
|
||||
load_map(m, file, strict)
|
||||
|
||||
# We expect these files to raise a UserWarning
|
||||
# and fail if there isn't one (or a different type
|
||||
# of exception)
|
||||
@raises(UserWarning)
|
||||
def assert_raises_userwarning(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
|
||||
print "Loading %s" % (file)
|
||||
|
||||
strict = True
|
||||
load_map(m, file, strict)
|
||||
|
||||
def test():
|
||||
success = 0
|
||||
failed = 0
|
||||
failed_tests = []
|
||||
|
||||
def test_broken_files():
|
||||
broken_files = glob.glob("../data/broken_maps/*.xml")
|
||||
# eh, can't glob this ... :-)
|
||||
broken_files.append( "../data/broken/does_not_exist.xml" )
|
||||
|
||||
# Add a filename that doesn't exist
|
||||
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 )
|
||||
yield assert_raises_userwarning, file
|
||||
|
||||
def test_good_files():
|
||||
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 )
|
||||
yield assert_loads_successfully, file
|
||||
|
|
|
@ -1,76 +1,42 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
from mapnik import *
|
||||
import os
|
||||
import sys
|
||||
import glob
|
||||
from nose.tools import *
|
||||
from utilities import execution_path
|
||||
|
||||
import os, sys, glob
|
||||
|
||||
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('.'))
|
||||
|
||||
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
|
||||
|
||||
# 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"
|
||||
|
||||
print "Loading map '%s' ... " % in_map
|
||||
|
||||
load_map(map, in_map)
|
||||
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;
|
||||
print "Saving map '%s' ... " % test_map
|
||||
|
||||
if not failed and os.path.exists( test_map ):
|
||||
print "Removing '" + test_map + "'"
|
||||
os.remove( test_map )
|
||||
save_map(map, test_map)
|
||||
new_map = Map(256, 256)
|
||||
|
||||
print "======================================================="
|
||||
print "Status:",
|
||||
if failed:
|
||||
print "FAILED"
|
||||
print "Reloading map '%s' ... " % test_map
|
||||
|
||||
load_map(new_map, test_map)
|
||||
|
||||
if os.path.exists(test_map):
|
||||
print "Removing '%s'" % test_map
|
||||
os.remove(test_map)
|
||||
else:
|
||||
print "SUCCESS"
|
||||
print "======================================================="
|
||||
return not failed
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if test():
|
||||
sys.exit( 0 )
|
||||
else:
|
||||
sys.exit( 1 )
|
||||
# Fail, the map wasn't written
|
||||
return False
|
||||
|
|
4
tests/python/utilities.py
Normal file
4
tests/python/utilities.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
import os, sys, inspect
|
||||
|
||||
def execution_path(filename):
|
||||
return os.path.join(os.path.dirname(sys._getframe(1).f_code.co_filename), filename)
|
Loading…
Reference in a new issue