+ 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
|
#!/usr/bin/python
|
||||||
|
|
||||||
from mapnik import *
|
from nose.tools import *
|
||||||
import sys
|
from mapnik import Map, load_map
|
||||||
import glob
|
from utilities import execution_path
|
||||||
|
|
||||||
def testGood( file ) :
|
import os, sys, glob
|
||||||
print "Testing good file '" + file + "' ... ",
|
|
||||||
|
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)
|
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 ) :
|
strict = True
|
||||||
print "Testing broken file '" + file + "' ... ",
|
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)
|
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():
|
def test_broken_files():
|
||||||
success = 0
|
|
||||||
failed = 0
|
|
||||||
failed_tests = []
|
|
||||||
|
|
||||||
broken_files = glob.glob("../data/broken_maps/*.xml")
|
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:
|
for file in broken_files:
|
||||||
if testBroken( file ):
|
yield assert_raises_userwarning, file
|
||||||
success += 1
|
|
||||||
else:
|
|
||||||
failed += 1
|
|
||||||
failed_tests.append( file )
|
|
||||||
|
|
||||||
|
def test_good_files():
|
||||||
good_files = glob.glob("../data/good_maps/*.xml")
|
good_files = glob.glob("../data/good_maps/*.xml")
|
||||||
|
|
||||||
for file in good_files:
|
for file in good_files:
|
||||||
if testGood( file ):
|
yield assert_loads_successfully, 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 )
|
|
||||||
|
|
|
@ -1,76 +1,42 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
from mapnik import *
|
from mapnik import *
|
||||||
import os
|
from nose.tools import *
|
||||||
import sys
|
from utilities import execution_path
|
||||||
import glob
|
|
||||||
|
|
||||||
|
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():
|
def test():
|
||||||
# success = 0
|
# TODO: Write a better test
|
||||||
# failed = 0
|
# 1. Construct map in memory
|
||||||
# failed_tests = []
|
# 2. Save map as XML
|
||||||
|
# 3. Load map to a second object
|
||||||
# TODO: write a better test
|
# 4. Compare both map objects
|
||||||
# 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)
|
map = Map(256, 256)
|
||||||
in_map = "../data/good_maps/osm-styles.xml"
|
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"
|
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:
|
print "Saving map '%s' ... " % test_map
|
||||||
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 ):
|
save_map(map, test_map)
|
||||||
print "Removing '" + test_map + "'"
|
new_map = Map(256, 256)
|
||||||
os.remove( test_map )
|
|
||||||
|
|
||||||
print "======================================================="
|
print "Reloading map '%s' ... " % test_map
|
||||||
print "Status:",
|
|
||||||
if failed:
|
load_map(new_map, test_map)
|
||||||
print "FAILED"
|
|
||||||
|
if os.path.exists(test_map):
|
||||||
|
print "Removing '%s'" % test_map
|
||||||
|
os.remove(test_map)
|
||||||
else:
|
else:
|
||||||
print "SUCCESS"
|
# Fail, the map wasn't written
|
||||||
print "======================================================="
|
return False
|
||||||
return not failed
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
if test():
|
|
||||||
sys.exit( 0 )
|
|
||||||
else:
|
|
||||||
sys.exit( 1 )
|
|
||||||
|
|
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…
Add table
Reference in a new issue