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 21:14:23 -0400
commit68ebc240a47cb235a186a01f887db318e0a55eba (patch)
treed6952ea73f9f2146635b15b66da176b1149e1c4e
parent444cdf61314e420c10f713ba7a5fa084b0b2dfd5 (diff)
[1.11.x] Fixed #28160 -- Prevented hiding GDAL exceptions when it's not installed.
Backport of 2dc3280254ae06ca1fe664abf55749fe12a699d4 from master
-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.py14
-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.py8
-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 dcdf153c36..a1329f89d9 100644
--- a/django/contrib/gis/serializers/geojson.py
+++ b/django/contrib/gis/serializers/geojson.py
@@ -1,12 +1,9 @@
from __future__ import unicode_literals
-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 78b221663f..1df98b1f23 100644
--- a/django/contrib/gis/utils/__init__.py
+++ b/django/contrib/gis/utils/__init__.py
@@ -1,17 +1,15 @@
"""
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.contrib.gis.utils.wkt import precision_wkt # 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 74d6019db6..640fa664ca 100644
--- a/tests/gis_tests/gdal_tests/test_driver.py
+++ b/tests/gis_tests/gdal_tests/test_driver.py
@@ -1,12 +1,8 @@
import unittest
-from django.contrib.gis.gdal import HAS_GDAL
+from django.contrib.gis.gdal import Driver, GDALException
from django.test import mock
-if HAS_GDAL:
- from django.contrib.gis.gdal import Driver, GDALException
-
-
valid_drivers = (
# vector
'ESRI Shapefile', 'MapInfo File', 'TIGER', 'S57', 'DGN', 'Memory', 'CSV',
@@ -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 8ea06ff426..f2957839d0 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(object):
@@ -13,7 +9,6 @@ class TestPoint(object):
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 bc8219772c..eb87e57230 100644
--- a/tests/gis_tests/gdal_tests/test_geom.py
+++ b/tests/gis_tests/gdal_tests/test_geom.py
@@ -1,9 +1,11 @@
import json
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 django.utils.six.moves import range
from ..test_data import TestDataMixin
@@ -14,14 +16,6 @@ except ImportError:
import pickle
-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 8649e9f231..96a995f36b 100644
--- a/tests/gis_tests/gdal_tests/test_raster.py
+++ b/tests/gis_tests/gdal_tests/test_raster.py
@@ -43,10 +43,10 @@ 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 django.utils import six
@@ -54,12 +54,7 @@ from django.utils._os import upath
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).
@@ -386,7 +381,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(upath(__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 d03d8dcfd3..2771896d09 100644
--- a/tests/gis_tests/gdal_tests/test_srs.py
+++ b/tests/gis_tests/gdal_tests/test_srs.py
@@ -2,12 +2,10 @@
from __future__ import unicode_literals
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:
@@ -151,7 +149,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 3338a32109..b7deacf989 100644
--- a/tests/gis_tests/geoapp/tests.py
+++ b/tests/gis_tests/geoapp/tests.py
@@ -81,11 +81,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 2aee39072d..554f1e8117 100644
--- a/tests/gis_tests/geos_tests/test_geos.py
+++ b/tests/gis_tests/geos_tests/test_geos.py
@@ -8,7 +8,6 @@ from io import BytesIO
from unittest import 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,
@@ -138,7 +137,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:
@@ -706,7 +704,6 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
pnt_wo_srid = Point(1, 1)
pnt_wo_srid.srid = pnt_wo_srid.srid
- @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]:
@@ -992,7 +989,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)')
@@ -1018,7 +1014,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)
@@ -1043,13 +1038,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,
@@ -1066,7 +1059,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 2b143fdf1b..f971c85548 100644
--- a/tests/gis_tests/inspectapp/tests.py
+++ b/tests/gis_tests/inspectapp/tests.py
@@ -3,7 +3,8 @@ from __future__ import unicode_literals
import os
import re
-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
@@ -12,12 +13,7 @@ from django.utils.six import StringIO
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 cf2c05f004..2f5fe58d48 100644
--- a/tests/gis_tests/layermap/tests.py
+++ b/tests/gis_tests/layermap/tests.py
@@ -7,13 +7,12 @@ 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
from django.utils._os import upath
-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 e0a7ff2a5a..9628fc0170 100644
--- a/tests/gis_tests/rasterapp/test_rasterfield.py
+++ b/tests/gis_tests/rasterapp/test_rasterfield.py
@@ -4,7 +4,7 @@ from django.contrib.gis.db.models.functions import Distance
from django.contrib.gis.db.models.lookups import (
DistanceLookupBase, gis_lookups,
)
-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
@@ -12,10 +12,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()