#NEWLINE# def run_tests( test_labels , verbosity = 1 , interactive = True , extra_tests = [ ] , suite = None ) : #NEWLINE# #INDENT# "\n    This module allows users to run tests for GIS apps that require the creation \n    of a spatial database.  Currently, this is only required for PostgreSQL as\n    PostGIS needs extra overhead in test database creation.\n\n    In order to create a PostGIS database, the DATABASE_USER (or \n    TEST_DATABASE_USER, if defined) will require superuser priviliges.  \n\n    To accomplish this outside the `postgres` user, you have a few options:\n      (A) Make your user a super user:\n        This may be done at the time the user is created, for example:\n        $ createuser --superuser <user_name>\n\n        Or you may alter the user's role from the SQL shell (assuming this\n        is done from an existing superuser role):\n        postgres# ALTER ROLE <user_name> SUPERUSER;\n\n      (B) Create your own PostgreSQL database as a local user:\n        1. Initialize database: `initdb -D /path/to/user/db`\n        2. If there's already a Postgres instance on the machine, it will need\n           to use a different TCP port than 5432. Edit postgresql.conf (in \n           /path/to/user/db) to change the database port (e.g. `port = 5433`).  \n        3. Start this database `pg_ctl -D /path/to/user/db start`\n\n      (C) On Windows platforms the pgAdmin III utility may also be used as \n        a simple way to add superuser privileges to your database user.\n\n    The TEST_RUNNER needs to be set in your settings like so:\n\n      TEST_RUNNER='django.contrib.gis.tests.run_tests'\n\n    Note: This test runner assumes that the PostGIS SQL files ('lwpostgis.sql'\n    and 'spatial_ref_sys.sql') are installed in the directory specified by \n    `pg_config --sharedir` (and defaults to /usr/local/share if that fails).\n    This behavior is overridden if POSTGIS_SQL_PATH is set in your settings.\n    \n    Windows users should set POSTGIS_SQL_PATH manually because the output\n    of `pg_config` uses paths like 'C:/PROGRA~1/POSTGR~1/..'.\n\n    Finally, the tests may be run by invoking `./manage.py test`.\n    " #NEWLINE# from django.conf import settings #NEWLINE# from django.db import connection #NEWLINE# from django.db.models import get_app , get_apps #NEWLINE# from django.test.simple import build_suite , build_test #NEWLINE# from django.test.utils import setup_test_environment , teardown_test_environment #NEWLINE# from django.contrib.gis.db.backend import create_spatial_db #NEWLINE# setup_test_environment ( ) #NEWLINE# settings . DEBUG = False #NEWLINE# old_name = settings . DATABASE_NAME #NEWLINE# if ( suite is None ) : #NEWLINE# #INDENT# suite = unittest . TestSuite ( ) #NEWLINE# if test_labels : #NEWLINE# #INDENT# for label in test_labels : #NEWLINE# #INDENT# if ( '.' in label ) : #NEWLINE# #INDENT# suite . addTest ( build_test ( label ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# app = get_app ( label ) #NEWLINE# suite . addTest ( build_suite ( app ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# for app in get_apps ( ) : #NEWLINE# #INDENT# suite . addTest ( build_suite ( app ) ) #NEWLINE# #UNINDENT# #UNINDENT# for test in extra_tests : #NEWLINE# #INDENT# suite . addTest ( test ) #NEWLINE# #UNINDENT# #UNINDENT# create_spatial_db ( test = True , verbosity = verbosity ) #NEWLINE# result = unittest . TextTestRunner ( verbosity = verbosity ) . run ( suite ) #NEWLINE# connection . creation . destroy_test_db ( old_name , verbosity ) #NEWLINE# teardown_test_environment ( ) #NEWLINE# return ( len ( result . failures ) + len ( result . errors ) )