summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2017-05-02 21:27:11 -0400
committerTim Graham <timograham@gmail.com>2017-05-04 20:45:18 -0400
commit2dc3280254ae06ca1fe664abf55749fe12a699d4 (patch)
treed331945d510ffdaed21dc67a99967f9586ac50b2
parent890537253cf235091816d27a5c2fb64943c8e34a (diff)
Fixed #28160 -- Prevented hiding GDAL exceptions when it's not installed.
-rw-r--r--django/contrib/gis/gdal/__init__.py41
-rw-r--r--django/contrib/gis/serializers/geojson.py5
-rw-r--r--django/contrib/gis/utils/__init__.py20
-rw-r--r--docs/ref/contrib/gis/install/geolibs.txt13
-rw-r--r--docs/releases/1.11.1.txt3
-rw-r--r--tests/gis_tests/gdal_tests/test_driver.py7
-rw-r--r--tests/gis_tests/gdal_tests/test_ds.py98
-rw-r--r--tests/gis_tests/gdal_tests/test_envelope.py7
-rw-r--r--tests/gis_tests/gdal_tests/test_geom.py13
-rw-r--r--tests/gis_tests/gdal_tests/test_raster.py10
-rw-r--r--tests/gis_tests/gdal_tests/test_srs.py9
-rw-r--r--tests/gis_tests/geoapp/tests.py9
-rw-r--r--tests/gis_tests/geos_tests/test_geos.py9
-rw-r--r--tests/gis_tests/inspectapp/tests.py10
-rw-r--r--tests/gis_tests/layermap/tests.py3
-rw-r--r--tests/gis_tests/rasterapp/models.py32
-rw-r--r--tests/gis_tests/rasterapp/test_rasterfield.py7
-rw-r--r--tests/test_runner/test_discover_runner.py4
18 files changed, 118 insertions, 182 deletions
diff --git a/django/contrib/gis/gdal/__init__.py b/django/contrib/gis/gdal/__init__.py
index 86ce62a068..4c217dd5b3 100644
--- a/django/contrib/gis/gdal/__init__.py
+++ b/django/contrib/gis/gdal/__init__.py
@@ -25,32 +25,23 @@
by setting `GDAL_LIBRARY_PATH` in your settings with the path to the GDAL C
library on your system.
"""
+from django.contrib.gis.gdal.datasource import DataSource
+from django.contrib.gis.gdal.driver import Driver
from django.contrib.gis.gdal.envelope import Envelope
-from django.contrib.gis.gdal.error import ( # NOQA
+from django.contrib.gis.gdal.error import (
GDALException, OGRException, OGRIndexError, SRSException, check_err,
)
-from django.contrib.gis.gdal.geomtype import OGRGeomType # NOQA
-
-__all__ = [
- 'check_err', 'Envelope', 'GDALException', 'OGRException', 'OGRIndexError',
- 'SRSException', 'OGRGeomType', 'HAS_GDAL',
-]
+from django.contrib.gis.gdal.geometries import OGRGeometry
+from django.contrib.gis.gdal.geomtype import OGRGeomType
+from django.contrib.gis.gdal.libgdal import (
+ GDAL_VERSION, gdal_full_version, gdal_version,
+)
+from django.contrib.gis.gdal.raster.source import GDALRaster
+from django.contrib.gis.gdal.srs import CoordTransform, SpatialReference
-# Attempting to import objects that depend on the GDAL library. The
-# HAS_GDAL flag will be set to True if the library is present on
-# the system.
-try:
- from django.contrib.gis.gdal.driver import Driver # NOQA
- from django.contrib.gis.gdal.datasource import DataSource # NOQA
- from django.contrib.gis.gdal.libgdal import gdal_version, gdal_full_version, GDAL_VERSION # NOQA
- from django.contrib.gis.gdal.raster.source import GDALRaster # NOQA
- from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform # NOQA
- from django.contrib.gis.gdal.geometries import OGRGeometry # NOQA
- HAS_GDAL = True
- __all__ += [
- 'Driver', 'DataSource', 'gdal_version', 'gdal_full_version',
- 'GDALRaster', 'GDAL_VERSION', 'SpatialReference', 'CoordTransform',
- 'OGRGeometry',
- ]
-except GDALException:
- HAS_GDAL = False
+__all__ = (
+ 'Driver', 'DataSource', 'CoordTransform', 'Envelope', 'GDALException',
+ 'GDALRaster', 'GDAL_VERSION', 'OGRException', 'OGRGeometry', 'OGRGeomType',
+ 'OGRIndexError', 'SpatialReference', 'SRSException',
+ 'check_err', 'gdal_version', 'gdal_full_version',
+)
diff --git a/django/contrib/gis/serializers/geojson.py b/django/contrib/gis/serializers/geojson.py
index fe3a32871f..4a62ea4251 100644
--- a/django/contrib/gis/serializers/geojson.py
+++ b/django/contrib/gis/serializers/geojson.py
@@ -1,10 +1,7 @@
-from django.contrib.gis.gdal import HAS_GDAL
+from django.contrib.gis.gdal import CoordTransform, SpatialReference
from django.core.serializers.base import SerializerDoesNotExist
from django.core.serializers.json import Serializer as JSONSerializer
-if HAS_GDAL:
- from django.contrib.gis.gdal import CoordTransform, SpatialReference
-
class Serializer(JSONSerializer):
"""
diff --git a/django/contrib/gis/utils/__init__.py b/django/contrib/gis/utils/__init__.py
index e59277d3a7..e66d3b2bd2 100644
--- a/django/contrib/gis/utils/__init__.py
+++ b/django/contrib/gis/utils/__init__.py
@@ -1,16 +1,14 @@
"""
This module contains useful utilities for GeoDjango.
"""
-from django.contrib.gis.gdal import HAS_GDAL
+from django.contrib.gis.utils.ogrinfo import ogrinfo # NOQA
+from django.contrib.gis.utils.ogrinspect import mapping, ogrinspect # NOQA
+from django.contrib.gis.utils.srs import add_srs_entry # NOQA
from django.core.exceptions import ImproperlyConfigured
-if HAS_GDAL:
- from django.contrib.gis.utils.ogrinfo import ogrinfo # NOQA
- from django.contrib.gis.utils.ogrinspect import mapping, ogrinspect # NOQA
- from django.contrib.gis.utils.srs import add_srs_entry # NOQA
- try:
- # LayerMapping requires DJANGO_SETTINGS_MODULE to be set,
- # so this needs to be in try/except.
- from django.contrib.gis.utils.layermapping import LayerMapping, LayerMapError # NOQA
- except ImproperlyConfigured:
- pass
+try:
+ # LayerMapping requires DJANGO_SETTINGS_MODULE to be set,
+ # so this needs to be in try/except.
+ from django.contrib.gis.utils.layermapping import LayerMapping, LayerMapError # NOQA
+except ImproperlyConfigured:
+ pass
diff --git a/docs/ref/contrib/gis/install/geolibs.txt b/docs/ref/contrib/gis/install/geolibs.txt
index 44132384e8..8d6281539b 100644
--- a/docs/ref/contrib/gis/install/geolibs.txt
+++ b/docs/ref/contrib/gis/install/geolibs.txt
@@ -225,17 +225,8 @@ Troubleshooting
Can't find GDAL library
^^^^^^^^^^^^^^^^^^^^^^^
-When GeoDjango can't find the GDAL library, the ``HAS_GDAL`` flag
-will be false:
-
-.. code-block:: pycon
-
- >>> from django.contrib.gis import gdal
- >>> gdal.HAS_GDAL
- False
-
-The solution is to properly configure your :ref:`libsettings` *or* set
-:ref:`gdallibrarypath` in your settings.
+When GeoDjango can't find the GDAL library, configure your :ref:`libsettings`
+*or* set :ref:`gdallibrarypath` in your settings.
.. _gdallibrarypath:
diff --git a/docs/releases/1.11.1.txt b/docs/releases/1.11.1.txt
index ba23d3e17e..e76ed491e9 100644
--- a/docs/releases/1.11.1.txt
+++ b/docs/releases/1.11.1.txt
@@ -94,3 +94,6 @@ Bugfixes
* Fixed ``QuerySet.prefetch_related()`` crash when fetching relations in nested
``Prefetch`` objects (:ticket:`27554`).
+
+* Prevented hiding GDAL errors if it's not installed when using ``contrib.gis``
+ (:ticket:`28160`). (It's a required dependency as of Django 1.11.)
diff --git a/tests/gis_tests/gdal_tests/test_driver.py b/tests/gis_tests/gdal_tests/test_driver.py
index 6e7e149ed7..c2dcc80d65 100644
--- a/tests/gis_tests/gdal_tests/test_driver.py
+++ b/tests/gis_tests/gdal_tests/test_driver.py
@@ -1,11 +1,7 @@
import unittest
from unittest import mock
-from django.contrib.gis.gdal import HAS_GDAL
-
-if HAS_GDAL:
- from django.contrib.gis.gdal import Driver, GDALException
-
+from django.contrib.gis.gdal import Driver, GDALException
valid_drivers = (
# vector
@@ -29,7 +25,6 @@ aliases = {
}
-@unittest.skipUnless(HAS_GDAL, "GDAL is required")
class DriverTest(unittest.TestCase):
def test01_valid_driver(self):
diff --git a/tests/gis_tests/gdal_tests/test_ds.py b/tests/gis_tests/gdal_tests/test_ds.py
index 0173ef1e4d..5b09032482 100644
--- a/tests/gis_tests/gdal_tests/test_ds.py
+++ b/tests/gis_tests/gdal_tests/test_ds.py
@@ -1,66 +1,64 @@
import os
import unittest
-from unittest import skipUnless
-from django.contrib.gis.gdal import HAS_GDAL
+from django.contrib.gis.gdal import (
+ GDAL_VERSION, DataSource, Envelope, GDALException, OGRGeometry,
+ OGRIndexError,
+)
+from django.contrib.gis.gdal.field import OFTInteger, OFTReal, OFTString
from ..test_data import TEST_DATA, TestDS, get_ds_file
-if HAS_GDAL:
- from django.contrib.gis.gdal import DataSource, Envelope, OGRGeometry, GDALException, OGRIndexError, GDAL_VERSION
- from django.contrib.gis.gdal.field import OFTReal, OFTInteger, OFTString
-
- # List of acceptable data sources.
- ds_list = (
- TestDS(
- 'test_point', nfeat=5, nfld=3, geom='POINT', gtype=1, driver='ESRI Shapefile',
- fields={'dbl': OFTReal, 'int': OFTInteger, 'str': OFTString},
- extent=(-1.35011, 0.166623, -0.524093, 0.824508), # Got extent from QGIS
- srs_wkt=(
- 'GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_1984",'
- '6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",'
- '0.017453292519943295]]'
- ),
- field_values={
- 'dbl': [float(i) for i in range(1, 6)],
- 'int': list(range(1, 6)),
- 'str': [str(i) for i in range(1, 6)],
- },
- fids=range(5)
+# List of acceptable data sources.
+ds_list = (
+ TestDS(
+ 'test_point', nfeat=5, nfld=3, geom='POINT', gtype=1, driver='ESRI Shapefile',
+ fields={'dbl': OFTReal, 'int': OFTInteger, 'str': OFTString},
+ extent=(-1.35011, 0.166623, -0.524093, 0.824508), # Got extent from QGIS
+ srs_wkt=(
+ 'GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_1984",'
+ '6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",'
+ '0.017453292519943295]]'
),
- TestDS(
- 'test_vrt', ext='vrt', nfeat=3, nfld=3, geom='POINT', gtype='Point25D',
- driver='OGR_VRT' if GDAL_VERSION >= (2, 0) else 'VRT',
- fields={
- 'POINT_X': OFTString,
- 'POINT_Y': OFTString,
- 'NUM': OFTString,
- }, # VRT uses CSV, which all types are OFTString.
- extent=(1.0, 2.0, 100.0, 523.5), # Min/Max from CSV
- field_values={
- 'POINT_X': ['1.0', '5.0', '100.0'],
- 'POINT_Y': ['2.0', '23.0', '523.5'],
- 'NUM': ['5', '17', '23'],
- },
- fids=range(1, 4)
+ field_values={
+ 'dbl': [float(i) for i in range(1, 6)],
+ 'int': list(range(1, 6)),
+ 'str': [str(i) for i in range(1, 6)],
+ },
+ fids=range(5)
+ ),
+ TestDS(
+ 'test_vrt', ext='vrt', nfeat=3, nfld=3, geom='POINT', gtype='Point25D',
+ driver='OGR_VRT' if GDAL_VERSION >= (2, 0) else 'VRT',
+ fields={
+ 'POINT_X': OFTString,
+ 'POINT_Y': OFTString,
+ 'NUM': OFTString,
+ }, # VRT uses CSV, which all types are OFTString.
+ extent=(1.0, 2.0, 100.0, 523.5), # Min/Max from CSV
+ field_values={
+ 'POINT_X': ['1.0', '5.0', '100.0'],
+ 'POINT_Y': ['2.0', '23.0', '523.5'],
+ 'NUM': ['5', '17', '23'],
+ },
+ fids=range(1, 4)
+ ),
+ TestDS(
+ 'test_poly', nfeat=3, nfld=3, geom='POLYGON', gtype=3,
+ driver='ESRI Shapefile',
+ fields={'float': OFTReal, 'int': OFTInteger, 'str': OFTString},
+ extent=(-1.01513, -0.558245, 0.161876, 0.839637), # Got extent from QGIS
+ srs_wkt=(
+ 'GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_1984",'
+ '6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",'
+ '0.017453292519943295]]'
),
- TestDS(
- 'test_poly', nfeat=3, nfld=3, geom='POLYGON', gtype=3,
- driver='ESRI Shapefile',
- fields={'float': OFTReal, 'int': OFTInteger, 'str': OFTString},
- extent=(-1.01513, -0.558245, 0.161876, 0.839637), # Got extent from QGIS
- srs_wkt=(
- 'GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_1984",'
- '6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",'
- '0.017453292519943295]]'
- ),
- )
)
+)
bad_ds = (TestDS('foo'),)
-@skipUnless(HAS_GDAL, "GDAL is required")
class DataSourceTest(unittest.TestCase):
def test01_valid_shp(self):
diff --git a/tests/gis_tests/gdal_tests/test_envelope.py b/tests/gis_tests/gdal_tests/test_envelope.py
index b6cf4ab4f3..c414bea533 100644
--- a/tests/gis_tests/gdal_tests/test_envelope.py
+++ b/tests/gis_tests/gdal_tests/test_envelope.py
@@ -1,10 +1,6 @@
import unittest
-from unittest import skipUnless
-from django.contrib.gis.gdal import HAS_GDAL
-
-if HAS_GDAL:
- from django.contrib.gis.gdal import Envelope, GDALException
+from django.contrib.gis.gdal import Envelope, GDALException
class TestPoint:
@@ -13,7 +9,6 @@ class TestPoint:
self.y = y
-@skipUnless(HAS_GDAL, "GDAL is required")
class EnvelopeTest(unittest.TestCase):
def setUp(self):
diff --git a/tests/gis_tests/gdal_tests/test_geom.py b/tests/gis_tests/gdal_tests/test_geom.py
index 4498ce7111..169857c0f2 100644
--- a/tests/gis_tests/gdal_tests/test_geom.py
+++ b/tests/gis_tests/gdal_tests/test_geom.py
@@ -2,20 +2,15 @@ import json
import pickle
import unittest
from binascii import b2a_hex
-from unittest import skipUnless
-from django.contrib.gis.gdal import HAS_GDAL
+from django.contrib.gis.gdal import (
+ CoordTransform, GDALException, OGRGeometry, OGRGeomType, OGRIndexError,
+ SpatialReference,
+)
from ..test_data import TestDataMixin
-if HAS_GDAL:
- from django.contrib.gis.gdal import (
- CoordTransform, GDALException, OGRGeometry, OGRGeomType, OGRIndexError,
- SpatialReference,
- )
-
-@skipUnless(HAS_GDAL, "GDAL is required")
class OGRGeomTest(unittest.TestCase, TestDataMixin):
"This tests the OGR Geometry."
diff --git a/tests/gis_tests/gdal_tests/test_raster.py b/tests/gis_tests/gdal_tests/test_raster.py
index cd850af9a1..9e23d78c68 100644
--- a/tests/gis_tests/gdal_tests/test_raster.py
+++ b/tests/gis_tests/gdal_tests/test_raster.py
@@ -43,21 +43,16 @@ Band 1 Block=163x50 Type=Byte, ColorInterp=Gray
import os
import struct
import tempfile
-import unittest
-from django.contrib.gis.gdal import HAS_GDAL
+from django.contrib.gis.gdal import GDAL_VERSION, GDALRaster
from django.contrib.gis.gdal.error import GDALException
+from django.contrib.gis.gdal.raster.band import GDALBand
from django.contrib.gis.shortcuts import numpy
from django.test import SimpleTestCase
from ..data.rasters.textrasters import JSON_RASTER
-if HAS_GDAL:
- from django.contrib.gis.gdal import GDALRaster, GDAL_VERSION
- from django.contrib.gis.gdal.raster.band import GDALBand
-
-@unittest.skipUnless(HAS_GDAL, "GDAL is required")
class GDALRasterTests(SimpleTestCase):
"""
Test a GDALRaster instance created from a file (GeoTiff).
@@ -383,7 +378,6 @@ class GDALRasterTests(SimpleTestCase):
)
-@unittest.skipUnless(HAS_GDAL, "GDAL is required")
class GDALBandTests(SimpleTestCase):
def setUp(self):
self.rs_path = os.path.join(os.path.dirname(__file__), '../data/rasters/raster.tif')
diff --git a/tests/gis_tests/gdal_tests/test_srs.py b/tests/gis_tests/gdal_tests/test_srs.py
index 9bc6c0a2c5..4179943e21 100644
--- a/tests/gis_tests/gdal_tests/test_srs.py
+++ b/tests/gis_tests/gdal_tests/test_srs.py
@@ -1,10 +1,8 @@
import unittest
-from unittest import skipUnless
-from django.contrib.gis.gdal import HAS_GDAL
-
-if HAS_GDAL:
- from django.contrib.gis.gdal import SpatialReference, CoordTransform, GDALException, SRSException
+from django.contrib.gis.gdal import (
+ CoordTransform, GDALException, SpatialReference, SRSException,
+)
class TestSRS:
@@ -148,7 +146,6 @@ bad_srlist = (
)
-@skipUnless(HAS_GDAL, "GDAL is required")
class SpatialRefTest(unittest.TestCase):
def test01_wkt(self):
diff --git a/tests/gis_tests/geoapp/tests.py b/tests/gis_tests/geoapp/tests.py
index e5c728078f..1ccac6fd1c 100644
--- a/tests/gis_tests/geoapp/tests.py
+++ b/tests/gis_tests/geoapp/tests.py
@@ -79,11 +79,10 @@ class GeoModelTest(TestCase):
self.assertEqual(ply, ns.poly)
# Testing the `ogr` and `srs` lazy-geometry properties.
- if gdal.HAS_GDAL:
- self.assertIsInstance(ns.poly.ogr, gdal.OGRGeometry)
- self.assertEqual(ns.poly.wkb, ns.poly.ogr.wkb)
- self.assertIsInstance(ns.poly.srs, gdal.SpatialReference)
- self.assertEqual('WGS 84', ns.poly.srs.name)
+ self.assertIsInstance(ns.poly.ogr, gdal.OGRGeometry)
+ self.assertEqual(ns.poly.wkb, ns.poly.ogr.wkb)
+ self.assertIsInstance(ns.poly.srs, gdal.SpatialReference)
+ self.assertEqual('WGS 84', ns.poly.srs.name)
# Changing the interior ring on the poly attribute.
new_inner = LinearRing((30, 30), (30, 70), (70, 70), (70, 30), (30, 30))
diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py
index 3270c75762..a3da015314 100644
--- a/tests/gis_tests/geos_tests/test_geos.py
+++ b/tests/gis_tests/geos_tests/test_geos.py
@@ -7,7 +7,6 @@ from io import BytesIO
from unittest import mock, skipUnless
from django.contrib.gis import gdal
-from django.contrib.gis.gdal import HAS_GDAL
from django.contrib.gis.geos import (
HAS_GEOS, GeometryCollection, GEOSException, GEOSGeometry, LinearRing,
LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon,
@@ -134,7 +133,6 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
self.assertEqual(srid, poly.shell.srid)
self.assertEqual(srid, fromstr(poly.ewkt).srid) # Checking export
- @skipUnless(HAS_GDAL, "GDAL is required.")
def test_json(self):
"Testing GeoJSON input/output (via GDAL)."
for g in self.geometries.json_geoms:
@@ -145,7 +143,6 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
self.assertEqual(json.loads(g.json), json.loads(geom.geojson))
self.assertEqual(GEOSGeometry(g.wkt, 4326), GEOSGeometry(geom.json))
- @skipUnless(HAS_GDAL, "GDAL is required.")
def test_json_srid(self):
geojson_data = {
"type": "Point",
@@ -730,7 +727,6 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
with self.assertRaisesMessage(ValueError, 'Input geometry already has SRID: %d.' % pnt.srid):
GEOSGeometry(pnt.ewkb, srid=1)
- @skipUnless(HAS_GDAL, "GDAL is required.")
def test_custom_srid(self):
"""Test with a null srid and a srid unknown to GDAL."""
for srid in [None, 999999]:
@@ -1016,7 +1012,6 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
# And, they should be equal.
self.assertEqual(gc1, gc2)
- @skipUnless(HAS_GDAL, "GDAL is required.")
def test_gdal(self):
"Testing `ogr` and `srs` properties."
g1 = fromstr('POINT(5 23)')
@@ -1042,7 +1037,6 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
self.assertNotEqual(poly._ptr, cpy1._ptr)
self.assertNotEqual(poly._ptr, cpy2._ptr)
- @skipUnless(HAS_GDAL, "GDAL is required to transform geometries")
def test_transform(self):
"Testing `transform` method."
orig = GEOSGeometry('POINT (-104.609 38.255)', 4326)
@@ -1067,13 +1061,11 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
self.assertAlmostEqual(trans.x, p.x, prec)
self.assertAlmostEqual(trans.y, p.y, prec)
- @skipUnless(HAS_GDAL, "GDAL is required to transform geometries")
def test_transform_3d(self):
p3d = GEOSGeometry('POINT (5 23 100)', 4326)
p3d.transform(2774)
self.assertEqual(p3d.z, 100)
- @skipUnless(HAS_GDAL, "GDAL is required.")
def test_transform_noop(self):
""" Testing `transform` method (SRID match) """
# transform() should no-op if source & dest SRIDs match,
@@ -1090,7 +1082,6 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
self.assertEqual(g1.srid, 4326)
self.assertIsNot(g1, g, "Clone didn't happen")
- @skipUnless(HAS_GDAL, "GDAL is required.")
def test_transform_nosrid(self):
""" Testing `transform` method (no SRID or negative SRID) """
diff --git a/tests/gis_tests/inspectapp/tests.py b/tests/gis_tests/inspectapp/tests.py
index ec0be801db..8a058d6a8e 100644
--- a/tests/gis_tests/inspectapp/tests.py
+++ b/tests/gis_tests/inspectapp/tests.py
@@ -2,7 +2,8 @@ import os
import re
from io import StringIO
-from django.contrib.gis.gdal import HAS_GDAL
+from django.contrib.gis.gdal import GDAL_VERSION, Driver, GDALException
+from django.contrib.gis.utils.ogrinspect import ogrinspect
from django.core.management import call_command
from django.db import connection, connections
from django.test import TestCase, skipUnlessDBFeature
@@ -10,12 +11,7 @@ from django.test.utils import modify_settings
from ..test_data import TEST_DATA
from ..utils import postgis
-
-if HAS_GDAL:
- from django.contrib.gis.gdal import Driver, GDALException, GDAL_VERSION
- from django.contrib.gis.utils.ogrinspect import ogrinspect
-
- from .models import AllOGRFields
+from .models import AllOGRFields
class InspectDbTests(TestCase):
diff --git a/tests/gis_tests/layermap/tests.py b/tests/gis_tests/layermap/tests.py
index 3e19697501..f03ff81592 100644
--- a/tests/gis_tests/layermap/tests.py
+++ b/tests/gis_tests/layermap/tests.py
@@ -4,12 +4,11 @@ from copy import copy
from decimal import Decimal
from django.conf import settings
-from django.contrib.gis.gdal import HAS_GDAL
from django.contrib.gis.geos import HAS_GEOS
from django.db import connection
from django.test import TestCase, override_settings
-if HAS_GEOS and HAS_GDAL:
+if HAS_GEOS:
from django.contrib.gis.utils.layermapping import (
LayerMapping, LayerMapError, InvalidDecimal, InvalidString,
MissingForeignKey,
diff --git a/tests/gis_tests/rasterapp/models.py b/tests/gis_tests/rasterapp/models.py
index c360d95716..e7769f19c4 100644
--- a/tests/gis_tests/rasterapp/models.py
+++ b/tests/gis_tests/rasterapp/models.py
@@ -1,23 +1,23 @@
from django.contrib.gis.db import models
-from django.contrib.gis.gdal import HAS_GDAL
-if HAS_GDAL:
- class RasterModel(models.Model):
- rast = models.RasterField('A Verbose Raster Name', null=True, srid=4326, spatial_index=True, blank=True)
- rastprojected = models.RasterField('A Projected Raster Table', srid=3086, null=True)
- geom = models.PointField(null=True)
- class Meta:
- required_db_features = ['supports_raster']
+class RasterModel(models.Model):
+ rast = models.RasterField('A Verbose Raster Name', null=True, srid=4326, spatial_index=True, blank=True)
+ rastprojected = models.RasterField('A Projected Raster Table', srid=3086, null=True)
+ geom = models.PointField(null=True)
- def __str__(self):
- return str(self.id)
+ class Meta:
+ required_db_features = ['supports_raster']
- class RasterRelatedModel(models.Model):
- rastermodel = models.ForeignKey(RasterModel, models.CASCADE)
+ def __str__(self):
+ return str(self.id)
- class Meta:
- required_db_features = ['supports_raster']
- def __str__(self):
- return str(self.id)
+class RasterRelatedModel(models.Model):
+ rastermodel = models.ForeignKey(RasterModel, models.CASCADE)
+
+ class Meta:
+ required_db_features = ['supports_raster']
+
+ def __str__(self):
+ return str(self.id)
diff --git a/tests/gis_tests/rasterapp/test_rasterfield.py b/tests/gis_tests/rasterapp/test_rasterfield.py
index 68df5dc0aa..df2b448a7e 100644
--- a/tests/gis_tests/rasterapp/test_rasterfield.py
+++ b/tests/gis_tests/rasterapp/test_rasterfield.py
@@ -3,7 +3,7 @@ import json
from django.contrib.gis.db.models.fields import BaseSpatialField
from django.contrib.gis.db.models.functions import Distance
from django.contrib.gis.db.models.lookups import DistanceLookupBase, GISLookup
-from django.contrib.gis.gdal import HAS_GDAL
+from django.contrib.gis.gdal import GDALRaster
from django.contrib.gis.geos import GEOSGeometry
from django.contrib.gis.measure import D
from django.contrib.gis.shortcuts import numpy
@@ -11,10 +11,7 @@ from django.db.models import Q
from django.test import TransactionTestCase, skipUnlessDBFeature
from ..data.rasters.textrasters import JSON_RASTER
-
-if HAS_GDAL:
- from django.contrib.gis.gdal import GDALRaster
- from .models import RasterModel, RasterRelatedModel
+from .models import RasterModel, RasterRelatedModel
@skipUnlessDBFeature('supports_raster')
diff --git a/tests/test_runner/test_discover_runner.py b/tests/test_runner/test_discover_runner.py
index 3ea563d1e6..3908f0a9da 100644
--- a/tests/test_runner/test_discover_runner.py
+++ b/tests/test_runner/test_discover_runner.py
@@ -135,8 +135,8 @@ class DiscoverRunnerTest(TestCase):
"""
Tests shouldn't be discovered twice when discovering on overlapping paths.
"""
- base_app = 'gis_tests'
- sub_app = 'gis_tests.geo3d'
+ base_app = 'forms_tests'
+ sub_app = 'forms_tests.field_tests'
with self.modify_settings(INSTALLED_APPS={'append': sub_app}):
single = DiscoverRunner().build_suite([base_app]).countTestCases()
dups = DiscoverRunner().build_suite([base_app, sub_app]).countTestCases()