2009-04-15 23:42:25 +02:00
#!/usr/bin/env python
2009-04-16 19:22:38 +02:00
2012-08-17 18:47:47 +02:00
import sys
try :
import nose
2013-04-06 07:51:53 +02:00
except ImportError , e :
sys . stderr . write ( " Unable to run python tests: the third party ' nose ' module is required \n To install ' nose ' do: \n \t sudo pip install nose (or on debian systems: apt-get install python-nose): %s \n " % e )
2012-08-17 18:47:47 +02:00
sys . exit ( 1 )
2014-07-25 03:58:03 +02:00
2014-07-25 20:49:05 +02:00
import mapnik
2009-04-16 19:22:38 +02:00
from python_tests . utilities import TodoPlugin
2010-03-18 21:05:08 +01:00
from nose . plugins . doctests import Doctest
2009-04-16 19:22:38 +02:00
2009-04-15 23:42:25 +02:00
import nose , sys , os , getopt
def usage ( ) :
2011-07-12 21:55:26 +02:00
print ( " test.py -h | --help " )
print ( " test.py [-q | -v] [-p | --prefix <path>] " )
2009-04-15 23:42:25 +02:00
def main ( ) :
try :
opts , args = getopt . getopt ( sys . argv [ 1 : ] , " hvqp: " , [ " help " , " prefix= " ] )
2011-12-14 02:02:00 +01:00
except getopt . GetoptError , err :
2011-07-12 21:55:26 +02:00
print ( str ( err ) )
2009-04-15 23:42:25 +02:00
usage ( )
sys . exit ( 2 )
prefix = None
verbose = False
quiet = False
for o , a in opts :
if o == " -q " :
quiet = True
elif o == " -v " :
verbose = True
elif o in ( " -h " , " --help " ) :
usage ( )
sys . exit ( )
elif o in ( " -p " , " --prefix " ) :
prefix = a
else :
2009-04-16 01:06:18 +02:00
assert False , " Unhandled option "
2012-02-24 22:13:56 +01:00
2009-04-15 23:42:25 +02:00
if quiet and verbose :
usage ( )
sys . exit ( 2 )
2012-02-24 22:13:56 +01:00
2009-04-15 23:42:25 +02:00
if prefix :
# Allow python to find libraries for testing on the buildbot
sys . path . insert ( 0 , os . path . join ( prefix , " lib/python %s /site-packages " % sys . version [ : 3 ] ) )
2011-11-23 12:33:58 +01:00
import mapnik
2009-04-15 23:42:25 +02:00
if not quiet :
2011-11-23 12:33:58 +01:00
print ( " - mapnik path: %s " % mapnik . __file__ )
if hasattr ( mapnik , ' _mapnik ' ) :
print ( " - _mapnik.so path: %s " % mapnik . _mapnik . __file__ )
2014-10-16 03:40:07 +02:00
if hasattr ( mapnik , ' inputpluginspath ' ) :
print ( " - Input plugins path: %s " % mapnik . inputpluginspath )
if os . environ . has_key ( ' MAPNIK_INPUT_PLUGINS_DIRECTORY ' ) :
print ( " - MAPNIK_INPUT_PLUGINS_DIRECTORY env: %s " % os . environ . get ( ' MAPNIK_INPUT_PLUGINS_DIRECTORY ' ) )
if hasattr ( mapnik , ' fontscollectionpath ' ) :
print ( " - Font path: %s " % mapnik . fontscollectionpath )
if os . environ . has_key ( ' MAPNIK_FONT_DIRECTORY ' ) :
print ( " - MAPNIK_FONT_DIRECTORY env: %s " % os . environ . get ( ' MAPNIK_FONT_DIRECTORY ' ) )
2011-09-02 23:57:14 +02:00
print ( ' ' )
2011-07-12 21:55:26 +02:00
print ( " - Running nosetests: " )
2011-09-02 23:57:14 +02:00
print ( ' ' )
2009-04-15 23:42:25 +02:00
2010-03-18 21:05:08 +01:00
argv = [ __file__ , ' --exe ' , ' --with-todo ' , ' --with-doctest ' , ' --doctest-tests ' ]
2009-04-15 23:42:25 +02:00
if not quiet :
argv . append ( ' -v ' )
if verbose :
2009-04-16 01:06:18 +02:00
# 3 * '-v' gets us debugging information from nose
2009-04-15 23:42:25 +02:00
argv . append ( ' -v ' )
argv . append ( ' -v ' )
2012-02-24 22:13:56 +01:00
2013-02-23 10:35:31 +01:00
dirname = os . path . dirname ( sys . argv [ 0 ] )
argv . extend ( [ ' -w ' , os . path . join ( dirname , ' python_tests ' ) ] )
2009-04-15 23:42:25 +02:00
2010-03-18 21:05:08 +01:00
if not nose . run ( argv = argv , plugins = [ TodoPlugin ( ) , Doctest ( ) ] ) :
2009-04-16 19:59:38 +02:00
sys . exit ( 1 )
else :
sys . exit ( 0 )
2009-04-15 23:42:25 +02:00
if __name__ == " __main__ " :
main ( )