Skip GeometryFieldTest if there's no spacial database.

This commit is contained in:
Julien Phalip 2012-06-16 13:57:33 -07:00
parent 5bdd0d6b6a
commit 1794e36fa1
3 changed files with 25 additions and 21 deletions

View File

@ -6,7 +6,7 @@
reference system to another.
Driver: Wraps an OGR data source driver.
DataSource: Wrapper for the OGR data source object, supports
OGR-supported data sources.
@ -20,15 +20,15 @@
SpatialReference: Represents OSR Spatial Reference objects.
The GDAL library will be imported from the system path using the default
The GDAL library will be imported from the system path using the default
library name for the current OS. The default library path may be overridden
by setting `GDAL_LIBRARY_PATH` in your settings with the path to the GDAL C
library on your system.
by setting `GDAL_LIBRARY_PATH` in your settings with the path to the GDAL C
library on your system.
GDAL links to a large number of external libraries that consume RAM when
GDAL links to a large number of external libraries that consume RAM when
loaded. Thus, it may desirable to disable GDAL on systems with limited
RAM resources -- this may be accomplished by setting `GDAL_LIBRARY_PATH`
to a non-existant file location (e.g., `GDAL_LIBRARY_PATH='/null/path'`;
to a non-existant file location (e.g., `GDAL_LIBRARY_PATH='/null/path'`;
setting to None/False/'' will not work as a string must be given).
"""
# Attempting to import objects that depend on the GDAL library. The
@ -44,6 +44,18 @@ try:
except:
HAS_GDAL, GEOJSON = False, False
from django.contrib.gis.tests.utils import no_mysql, oracle, postgis, spatialite
HAS_SPATIALREFSYS = True
if oracle:
from django.contrib.gis.db.backends.oracle.models import SpatialRefSys
elif postgis:
from django.contrib.gis.db.backends.postgis.models import SpatialRefSys
elif spatialite:
from django.contrib.gis.db.backends.spatialite.models import SpatialRefSys
else:
HAS_SPATIALREFSYS = False
SpatialRefSys = None
try:
from django.contrib.gis.gdal.envelope import Envelope
except ImportError:

View File

@ -1,11 +1,13 @@
from django.forms import ValidationError
from django.contrib.gis import forms
from django.contrib.gis.gdal import HAS_GDAL
from django.contrib.gis.geos import GEOSGeometry
from django.contrib.gis.gdal import HAS_GDAL, HAS_SPATIALREFSYS
from django.utils import unittest
@unittest.skipUnless(HAS_GDAL, "GeometryFieldTest needs gdal support")
if HAS_SPATIALREFSYS:
from django.contrib.gis import forms
from django.contrib.gis.geos import GEOSGeometry
@unittest.skipUnless(HAS_GDAL and HAS_SPATIALREFSYS, "GeometryFieldTest needs gdal support and a spatial database")
class GeometryFieldTest(unittest.TestCase):
def test00_init(self):

View File

@ -1,5 +1,5 @@
from django.db import connection
from django.contrib.gis.gdal import HAS_GDAL
from django.contrib.gis.gdal import HAS_GDAL, HAS_SPATIALREFSYS, SpatialRefSys
from django.contrib.gis.tests.utils import no_mysql, oracle, postgis, spatialite
from django.utils import unittest
@ -28,16 +28,6 @@ test_srs = ({'srid' : 4326,
},
)
HAS_SPATIALREFSYS = True
if oracle:
from django.contrib.gis.db.backends.oracle.models import SpatialRefSys
elif postgis:
from django.contrib.gis.db.backends.postgis.models import SpatialRefSys
elif spatialite:
from django.contrib.gis.db.backends.spatialite.models import SpatialRefSys
else:
HAS_SPATIALREFSYS = False
@unittest.skipUnless(HAS_GDAL and HAS_SPATIALREFSYS,
"SpatialRefSysTest needs gdal support and a spatial database")
class SpatialRefSysTest(unittest.TestCase):