1
0
mirror of https://github.com/django/django.git synced 2025-07-04 01:39:20 +00:00

gis: Now plays nice with the Django test suite if the spatial prerequisites aren't installed.

git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@8155 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Justin Bronn 2008-07-30 17:46:02 +00:00
parent 2135e10739
commit 45b73c9a46
2 changed files with 25 additions and 6 deletions

View File

@ -211,9 +211,23 @@ class SpatialRefSysMixin(object):
# The SpatialRefSys and GeometryColumns models # The SpatialRefSys and GeometryColumns models
_srid_info = True _srid_info = True
if settings.DATABASE_ENGINE == 'postgresql_psycopg2': if settings.DATABASE_ENGINE == 'postgresql_psycopg2':
# Because the PostGIS version is checked when initializing the spatial
# backend a `ProgrammingError` will be raised if the PostGIS tables
# and functions are not installed. We catch here so it won't be raised when
# running the Django test suite.
from psycopg2 import ProgrammingError
try:
from django.contrib.gis.db.backend.postgis.models import GeometryColumns, SpatialRefSys from django.contrib.gis.db.backend.postgis.models import GeometryColumns, SpatialRefSys
except ProgrammingError:
_srid_info = False
elif settings.DATABASE_ENGINE == 'oracle': elif settings.DATABASE_ENGINE == 'oracle':
# Same thing as above, except the GEOS library is attempted to be loaded for
# `BaseSpatialBackend`, and an exception will be raised during the
# Django test suite if it doesn't exist.
try:
from django.contrib.gis.db.backend.oracle.models import GeometryColumns, SpatialRefSys from django.contrib.gis.db.backend.oracle.models import GeometryColumns, SpatialRefSys
except:
_srid_info = False
else: else:
_srid_info = False _srid_info = False

View File

@ -44,8 +44,13 @@ if HAS_GEOIP:
if hasattr(settings, 'GEOIP_PATH'): if hasattr(settings, 'GEOIP_PATH'):
test_suite_names.append('test_geoip') test_suite_names.append('test_geoip')
def suite(): def geo_suite():
"Builds a test suite for the GIS package." """
Builds a test suite for the GIS package. This is not named
`suite` so it will not interfere with the Django test suite (since
spatial database tables are required to execute these tests on
some backends).
"""
s = TestSuite() s = TestSuite()
for test_suite in test_suite_names: for test_suite in test_suite_names:
tsuite = getattr(__import__('django.contrib.gis.tests', globals(), locals(), [test_suite]),test_suite) tsuite = getattr(__import__('django.contrib.gis.tests', globals(), locals(), [test_suite]),test_suite)
@ -54,7 +59,7 @@ def suite():
def run(verbosity=1): def run(verbosity=1):
"Runs the tests that do not require geographic (GEOS, GDAL, etc.) models." "Runs the tests that do not require geographic (GEOS, GDAL, etc.) models."
TextTestRunner(verbosity=verbosity).run(suite()) TextTestRunner(verbosity=verbosity).run(geo_suite())
def run_tests(module_list, verbosity=1, interactive=True): def run_tests(module_list, verbosity=1, interactive=True):
""" """
@ -105,7 +110,7 @@ def run_tests(module_list, verbosity=1, interactive=True):
# Creating the test suite, adding the test models to INSTALLED_APPS, and # Creating the test suite, adding the test models to INSTALLED_APPS, and
# adding the model test suites to our suite package. # adding the model test suites to our suite package.
test_suite = suite() test_suite = geo_suite()
for test_model in test_models: for test_model in test_models:
module_name = 'django.contrib.gis.tests.%s' % test_model module_name = 'django.contrib.gis.tests.%s' % test_model
if mysql: if mysql: