Skip to content

Commit 1794e36

Browse files
committed
Skip GeometryFieldTest if there's no spacial database.
1 parent 5bdd0d6 commit 1794e36

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

django/contrib/gis/gdal/__init__.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
reference system to another.
77
88
Driver: Wraps an OGR data source driver.
9-
9+
1010
DataSource: Wrapper for the OGR data source object, supports
1111
OGR-supported data sources.
1212
@@ -20,15 +20,15 @@
2020
2121
SpatialReference: Represents OSR Spatial Reference objects.
2222
23-
The GDAL library will be imported from the system path using the default
23+
The GDAL library will be imported from the system path using the default
2424
library name for the current OS. The default library path may be overridden
25-
by setting `GDAL_LIBRARY_PATH` in your settings with the path to the GDAL C
26-
library on your system.
25+
by setting `GDAL_LIBRARY_PATH` in your settings with the path to the GDAL C
26+
library on your system.
2727
28-
GDAL links to a large number of external libraries that consume RAM when
28+
GDAL links to a large number of external libraries that consume RAM when
2929
loaded. Thus, it may desirable to disable GDAL on systems with limited
3030
RAM resources -- this may be accomplished by setting `GDAL_LIBRARY_PATH`
31-
to a non-existant file location (e.g., `GDAL_LIBRARY_PATH='/null/path'`;
31+
to a non-existant file location (e.g., `GDAL_LIBRARY_PATH='/null/path'`;
3232
setting to None/False/'' will not work as a string must be given).
3333
"""
3434
# Attempting to import objects that depend on the GDAL library. The
@@ -44,6 +44,18 @@
4444
except:
4545
HAS_GDAL, GEOJSON = False, False
4646

47+
from django.contrib.gis.tests.utils import no_mysql, oracle, postgis, spatialite
48+
HAS_SPATIALREFSYS = True
49+
if oracle:
50+
from django.contrib.gis.db.backends.oracle.models import SpatialRefSys
51+
elif postgis:
52+
from django.contrib.gis.db.backends.postgis.models import SpatialRefSys
53+
elif spatialite:
54+
from django.contrib.gis.db.backends.spatialite.models import SpatialRefSys
55+
else:
56+
HAS_SPATIALREFSYS = False
57+
SpatialRefSys = None
58+
4759
try:
4860
from django.contrib.gis.gdal.envelope import Envelope
4961
except ImportError:

django/contrib/gis/tests/test_geoforms.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from django.forms import ValidationError
2-
from django.contrib.gis import forms
3-
from django.contrib.gis.gdal import HAS_GDAL
4-
from django.contrib.gis.geos import GEOSGeometry
2+
from django.contrib.gis.gdal import HAS_GDAL, HAS_SPATIALREFSYS
53
from django.utils import unittest
64

75

8-
@unittest.skipUnless(HAS_GDAL, "GeometryFieldTest needs gdal support")
6+
if HAS_SPATIALREFSYS:
7+
from django.contrib.gis import forms
8+
from django.contrib.gis.geos import GEOSGeometry
9+
10+
@unittest.skipUnless(HAS_GDAL and HAS_SPATIALREFSYS, "GeometryFieldTest needs gdal support and a spatial database")
911
class GeometryFieldTest(unittest.TestCase):
1012

1113
def test00_init(self):

django/contrib/gis/tests/test_spatialrefsys.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from django.db import connection
2-
from django.contrib.gis.gdal import HAS_GDAL
2+
from django.contrib.gis.gdal import HAS_GDAL, HAS_SPATIALREFSYS, SpatialRefSys
33
from django.contrib.gis.tests.utils import no_mysql, oracle, postgis, spatialite
44
from django.utils import unittest
55

@@ -28,16 +28,6 @@
2828
},
2929
)
3030

31-
HAS_SPATIALREFSYS = True
32-
if oracle:
33-
from django.contrib.gis.db.backends.oracle.models import SpatialRefSys
34-
elif postgis:
35-
from django.contrib.gis.db.backends.postgis.models import SpatialRefSys
36-
elif spatialite:
37-
from django.contrib.gis.db.backends.spatialite.models import SpatialRefSys
38-
else:
39-
HAS_SPATIALREFSYS = False
40-
4131
@unittest.skipUnless(HAS_GDAL and HAS_SPATIALREFSYS,
4232
"SpatialRefSysTest needs gdal support and a spatial database")
4333
class SpatialRefSysTest(unittest.TestCase):

0 commit comments

Comments
 (0)