summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Bronn <jbronn@gmail.com>2008-07-30 17:46:02 +0000
committerJustin Bronn <jbronn@gmail.com>2008-07-30 17:46:02 +0000
commit45b73c9a4685809236f84046cc7ffd32a50db958 (patch)
treefe49de7e8ccfdff69cf319175e8a1c894a451ae4
parent2135e10739e28dc518a54a5a4ce5358d7e714bd2 (diff)
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
-rw-r--r--django/contrib/gis/models.py18
-rw-r--r--django/contrib/gis/tests/__init__.py13
2 files changed, 25 insertions, 6 deletions
diff --git a/django/contrib/gis/models.py b/django/contrib/gis/models.py
index 3231f926ff..d3e8dbdb83 100644
--- a/django/contrib/gis/models.py
+++ b/django/contrib/gis/models.py
@@ -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
diff --git a/django/contrib/gis/tests/__init__.py b/django/contrib/gis/tests/__init__.py
index 44465f4f23..9bf1ccd936 100644
--- a/django/contrib/gis/tests/__init__.py
+++ b/django/contrib/gis/tests/__init__.py
@@ -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: