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:
parent
2135e10739
commit
45b73c9a46
@ -211,9 +211,23 @@ class SpatialRefSysMixin(object):
|
||||
# The SpatialRefSys and GeometryColumns models
|
||||
_srid_info = True
|
||||
if settings.DATABASE_ENGINE == 'postgresql_psycopg2':
|
||||
from django.contrib.gis.db.backend.postgis.models import GeometryColumns, SpatialRefSys
|
||||
# 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
|
||||
except ProgrammingError:
|
||||
_srid_info = False
|
||||
elif settings.DATABASE_ENGINE == 'oracle':
|
||||
from django.contrib.gis.db.backend.oracle.models import GeometryColumns, SpatialRefSys
|
||||
# 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
|
||||
except:
|
||||
_srid_info = False
|
||||
else:
|
||||
_srid_info = False
|
||||
|
||||
|
@ -44,8 +44,13 @@ if HAS_GEOIP:
|
||||
if hasattr(settings, 'GEOIP_PATH'):
|
||||
test_suite_names.append('test_geoip')
|
||||
|
||||
def suite():
|
||||
"Builds a test suite for the GIS package."
|
||||
def geo_suite():
|
||||
"""
|
||||
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()
|
||||
for test_suite in test_suite_names:
|
||||
tsuite = getattr(__import__('django.contrib.gis.tests', globals(), locals(), [test_suite]),test_suite)
|
||||
@ -54,7 +59,7 @@ def suite():
|
||||
|
||||
def run(verbosity=1):
|
||||
"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):
|
||||
"""
|
||||
@ -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
|
||||
# adding the model test suites to our suite package.
|
||||
test_suite = suite()
|
||||
test_suite = geo_suite()
|
||||
for test_model in test_models:
|
||||
module_name = 'django.contrib.gis.tests.%s' % test_model
|
||||
if mysql:
|
||||
|
Loading…
x
Reference in New Issue
Block a user