Skip to content

Commit

Permalink
Skip GeometryFieldTest if there's no spacial database.
Browse files Browse the repository at this point in the history
  • Loading branch information
jphalip committed Jun 16, 2012
1 parent 5bdd0d6 commit 1794e36
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
24 changes: 18 additions & 6 deletions django/contrib/gis/gdal/__init__.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
reference system to another. reference system to another.
Driver: Wraps an OGR data source driver. Driver: Wraps an OGR data source driver.
DataSource: Wrapper for the OGR data source object, supports DataSource: Wrapper for the OGR data source object, supports
OGR-supported data sources. OGR-supported data sources.
Expand All @@ -20,15 +20,15 @@
SpatialReference: Represents OSR Spatial Reference objects. 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 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 by setting `GDAL_LIBRARY_PATH` in your settings with the path to the GDAL C
library on your system. 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 loaded. Thus, it may desirable to disable GDAL on systems with limited
RAM resources -- this may be accomplished by setting `GDAL_LIBRARY_PATH` 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). setting to None/False/'' will not work as a string must be given).
""" """
# Attempting to import objects that depend on the GDAL library. The # Attempting to import objects that depend on the GDAL library. The
Expand All @@ -44,6 +44,18 @@
except: except:
HAS_GDAL, GEOJSON = False, False 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: try:
from django.contrib.gis.gdal.envelope import Envelope from django.contrib.gis.gdal.envelope import Envelope
except ImportError: except ImportError:
Expand Down
10 changes: 6 additions & 4 deletions django/contrib/gis/tests/test_geoforms.py
Original file line number Original file line Diff line number Diff line change
@@ -1,11 +1,13 @@
from django.forms import ValidationError from django.forms import ValidationError
from django.contrib.gis import forms from django.contrib.gis.gdal import HAS_GDAL, HAS_SPATIALREFSYS
from django.contrib.gis.gdal import HAS_GDAL
from django.contrib.gis.geos import GEOSGeometry
from django.utils import unittest 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): class GeometryFieldTest(unittest.TestCase):


def test00_init(self): def test00_init(self):
Expand Down
12 changes: 1 addition & 11 deletions django/contrib/gis/tests/test_spatialrefsys.py
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import connection 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.contrib.gis.tests.utils import no_mysql, oracle, postgis, spatialite
from django.utils import unittest from django.utils import unittest


Expand Down Expand Up @@ -28,16 +28,6 @@
}, },
) )


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, @unittest.skipUnless(HAS_GDAL and HAS_SPATIALREFSYS,
"SpatialRefSysTest needs gdal support and a spatial database") "SpatialRefSysTest needs gdal support and a spatial database")
class SpatialRefSysTest(unittest.TestCase): class SpatialRefSysTest(unittest.TestCase):
Expand Down

0 comments on commit 1794e36

Please sign in to comment.