diff --git a/django/contrib/gis/db/models/mixin.py b/django/contrib/gis/db/models/mixin.py index 603ceaa2eb..90640d1787 100644 --- a/django/contrib/gis/db/models/mixin.py +++ b/django/contrib/gis/db/models/mixin.py @@ -1,15 +1,10 @@ from warnings import warn -# GEOS is a requirement +# GEOS is a requirement, GDAL is not from django.contrib.gis.geos import GEOSGeometry - -# GDAL is a lot more complicated to install, and isn't necessary for many -# operations. -try: +from django.contrib.gis.gdal import HAS_GDAL +if HAS_GDAL: from django.contrib.gis.gdal import OGRGeometry, SpatialReference - HAS_GDAL = True -except ImportError, e: - HAS_GDAL = False # Until model subclassing is a possibility, a mixin class is used to add # the necessary functions that may be contributed for geographic objects. diff --git a/django/contrib/gis/tests/__init__.py b/django/contrib/gis/tests/__init__.py index 390fa8e037..8b64e06911 100644 --- a/django/contrib/gis/tests/__init__.py +++ b/django/contrib/gis/tests/__init__.py @@ -1,23 +1,23 @@ +import sys from copy import copy from unittest import TestSuite, TextTestRunner -import sys +from django.contrib.gis.gdal import HAS_GDAL + # Tests that do not require setting up and tearing down a spatial database. test_suite_names = [ 'test_geos', 'test_measure', ] -try: - # GDAL tests - import django.contrib.gis.gdal +if HAS_GDAL: test_suite_names += [ 'test_gdal_driver', 'test_gdal_ds', 'test_gdal_geom', 'test_gdal_srs', 'test_spatialrefsys', - ] -except ImportError, e: + ] +else: print >>sys.stderr, "GDAL not available - no GDAL tests will be run." test_models = ['geoapp'] @@ -35,27 +35,28 @@ def run(verbosity=1): TextTestRunner(verbosity=verbosity).run(suite()) def run_tests(module_list, verbosity=1, interactive=True): - """Run the tests that require creation of a spatial database. Does not - yet work on Windows platforms. + """ + Run the tests that require creation of a spatial database. Does not + yet work on Windows platforms. In order to run geographic model tests the DATABASE_USER will require - superuser priviliges. To accomplish this outside the `postgres` user, - create your own PostgreSQL database as a user: - (1) Initialize database: `initdb -D /path/to/user/db` - (2) If there's already a Postgres instance on the machine, it will need - to use a different TCP port than 5432. Edit postgresql.conf (in - /path/to/user/db) to change the database port (e.g. `port = 5433`). - (3) Start this database `pg_ctl -D /path/to/user/db start` + superuser priviliges. To accomplish this outside the `postgres` user, + create your own PostgreSQL database as a user: + (1) Initialize database: `initdb -D /path/to/user/db` + (2) If there's already a Postgres instance on the machine, it will need + to use a different TCP port than 5432. Edit postgresql.conf (in + /path/to/user/db) to change the database port (e.g. `port = 5433`). + (3) Start this database `pg_ctl -D /path/to/user/db start` Make sure your settings.py matches the settings of the user database. For example, set the - same port number (`DATABASE_PORT=5433`). DATABASE_NAME or TEST_DATABSE_NAME must be set, - along with DATABASE_USER. + same port number (`DATABASE_PORT=5433`). DATABASE_NAME or TEST_DATABSE_NAME must be set, + along with DATABASE_USER. In settings.py set TEST_RUNNER='django.contrib.gis.tests.run_tests'. Finally, this assumes that the PostGIS SQL files (lwpostgis.sql and spatial_ref_sys.sql) - are installed in /usr/local/share. If they are not, add `POSTGIS_SQL_PATH=/path/to/sql` - in your settings.py. + are installed in /usr/local/share. If they are not, add `POSTGIS_SQL_PATH=/path/to/sql` + in your settings.py. The tests may be run by invoking `./manage.py test`. """