[1.11.x] Made runtests.py run gis_tests only when using a GIS database backend.

This facilitates other changes like refs #28160.

Backport of 890537253c from master
This commit is contained in:
Tim Graham 2017-05-04 10:14:35 -04:00
parent c679ac0449
commit 444cdf6131
27 changed files with 31 additions and 91 deletions

View File

@ -12,7 +12,6 @@ class NamedModel(models.Model):
class Meta:
abstract = True
required_db_features = ['gis_enabled']
def __str__(self):
return self.name

View File

@ -19,7 +19,6 @@ from .models import (
)
@skipUnlessDBFeature("gis_enabled")
class DistanceTest(TestCase):
fixtures = ['initial']
@ -463,7 +462,6 @@ Perimeter(geom1) | OK | :-(
''' # NOQA
@skipUnlessDBFeature("gis_enabled")
class DistanceFunctionsTests(TestCase):
fixtures = ['initial']

View File

@ -10,7 +10,6 @@ class NamedModel(models.Model):
class Meta:
abstract = True
required_db_features = ['gis_enabled']
def __str__(self):
return self.name
@ -49,7 +48,6 @@ class SimpleModel(models.Model):
class Meta:
abstract = True
required_db_features = ['gis_enabled']
class Point2D(SimpleModel):

View File

@ -97,7 +97,7 @@ class Geo3DLoadingHelper(object):
Polygon3D.objects.create(name='3D BBox', poly=bbox_3d)
@skipUnlessDBFeature("gis_enabled", "supports_3d_storage")
@skipUnlessDBFeature("supports_3d_storage")
class Geo3DTest(Geo3DLoadingHelper, TestCase):
"""
Only a subset of the PostGIS routines are 3D-enabled, and this TestCase
@ -310,7 +310,7 @@ class Geo3DTest(Geo3DLoadingHelper, TestCase):
self.assertEqual(city_dict[city.name][2] + ztrans, city.translate.z)
@skipUnlessDBFeature("gis_enabled", "supports_3d_functions")
@skipUnlessDBFeature("supports_3d_functions")
class Geo3DFunctionsTests(Geo3DLoadingHelper, TestCase):
def test_kml(self):
"""

View File

@ -11,7 +11,6 @@ class City(models.Model):
class Meta:
app_label = 'geoadmin'
required_db_features = ['gis_enabled']
def __str__(self):
return self.name

View File

@ -2,14 +2,13 @@ from __future__ import unicode_literals
from django.contrib.gis import admin
from django.contrib.gis.geos import Point
from django.test import TestCase, override_settings, skipUnlessDBFeature
from django.test import TestCase, override_settings
from django.test.utils import patch_logger
from .admin import UnmodifiableAdmin
from .models import City, site
@skipUnlessDBFeature("gis_enabled")
@override_settings(ROOT_URLCONF='django.contrib.gis.tests.geoadmin.urls')
class GeoAdminTest(TestCase):

View File

@ -12,7 +12,6 @@ class NamedModel(models.Model):
class Meta:
abstract = True
required_db_features = ['gis_enabled']
def __str__(self):
return self.name
@ -31,7 +30,6 @@ class City(NamedModel):
class Meta:
app_label = 'geoapp'
required_db_features = ['gis_enabled']
# This is an inherited model from City
@ -41,7 +39,6 @@ class PennsylvaniaCity(City):
class Meta:
app_label = 'geoapp'
required_db_features = ['gis_enabled']
class State(NamedModel):
@ -49,7 +46,6 @@ class State(NamedModel):
class Meta:
app_label = 'geoapp'
required_db_features = ['gis_enabled']
class Track(NamedModel):
@ -61,9 +57,6 @@ class MultiFields(NamedModel):
point = models.PointField()
poly = models.PolygonField()
class Meta:
required_db_features = ['gis_enabled']
class UniqueTogetherModel(models.Model):
city = models.CharField(max_length=30)
@ -71,15 +64,12 @@ class UniqueTogetherModel(models.Model):
class Meta:
unique_together = ('city', 'point')
required_db_features = ['gis_enabled', 'supports_geometry_field_unique_index']
required_db_features = ['supports_geometry_field_unique_index']
class Truth(models.Model):
val = models.BooleanField(default=False)
class Meta:
required_db_features = ['gis_enabled']
class Feature(NamedModel):
geom = models.GeometryField()
@ -88,9 +78,6 @@ class Feature(NamedModel):
class MinusOneSRID(models.Model):
geom = models.PointField(srid=-1) # Minus one SRID.
class Meta:
required_db_features = ['gis_enabled']
class NonConcreteField(models.IntegerField):

View File

@ -8,7 +8,6 @@ from ..utils import postgis
from .models import City
@skipUnlessDBFeature('gis_enabled')
class GeoExpressionsTests(TestCase):
fixtures = ['initial']

View File

@ -4,16 +4,13 @@ from xml.dom import minidom
from django.conf import settings
from django.contrib.sites.models import Site
from django.test import (
TestCase, modify_settings, override_settings, skipUnlessDBFeature,
)
from django.test import TestCase, modify_settings, override_settings
from .models import City
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.sites'})
@override_settings(ROOT_URLCONF='gis_tests.geoapp.urls')
@skipUnlessDBFeature("gis_enabled")
class GeoFeedTest(TestCase):
fixtures = ['initial']

View File

@ -15,7 +15,6 @@ from ..utils import mysql, oracle, postgis, spatialite
from .models import City, Country, CountryWebMercator, State, Track
@skipUnlessDBFeature("gis_enabled")
class GISFunctionsTests(TestCase):
"""
Testing functions from django/contrib/gis/db/models/functions.py.

View File

@ -12,7 +12,6 @@ from ..utils import no_oracle
from .models import City, PennsylvaniaCity, State, Truth
@skipUnlessDBFeature("gis_enabled")
class GeoRegressionTests(TestCase):
fixtures = ['initial']

View File

@ -4,12 +4,11 @@ import json
from django.contrib.gis.geos import LinearRing, Point, Polygon
from django.core import serializers
from django.test import TestCase, skipUnlessDBFeature
from django.test import TestCase
from .models import City, MultiFields, PennsylvaniaCity
@skipUnlessDBFeature("gis_enabled")
class GeoJSONSerializerTests(TestCase):
fixtures = ['initial']

View File

@ -6,16 +6,13 @@ from xml.dom import minidom
from django.conf import settings
from django.contrib.sites.models import Site
from django.test import (
TestCase, modify_settings, override_settings, skipUnlessDBFeature,
)
from django.test import TestCase, modify_settings, override_settings
from .models import City, Country
@modify_settings(INSTALLED_APPS={'append': ['django.contrib.sites', 'django.contrib.sitemaps']})
@override_settings(ROOT_URLCONF='gis_tests.geoapp.urls')
@skipUnlessDBFeature("gis_enabled")
class GeoSitemapTest(TestCase):
def setUp(self):

View File

@ -22,7 +22,6 @@ from .models import (
)
@skipUnlessDBFeature("gis_enabled")
class GeoModelTest(TestCase):
fixtures = ['initial']
@ -223,7 +222,6 @@ class GeoModelTest(TestCase):
self.assertEqual(feature.geom.srid, g.srid)
@skipUnlessDBFeature("gis_enabled")
class GeoLookupTest(TestCase):
fixtures = ['initial']
@ -450,7 +448,6 @@ class GeoLookupTest(TestCase):
self.assertEqual('Lawrence', City.objects.get(point__relate=(ks.poly, intersects_mask)).name)
@skipUnlessDBFeature("gis_enabled")
@ignore_warnings(category=RemovedInDjango20Warning)
class GeoQuerySetTest(TestCase):
fixtures = ['initial']

View File

@ -10,7 +10,6 @@ class NamedModel(models.Model):
class Meta:
abstract = True
required_db_features = ['gis_enabled']
def __str__(self):
return self.name
@ -21,7 +20,6 @@ class City(NamedModel):
class Meta:
app_label = 'geogapp'
required_db_features = ['gis_enabled']
class Zipcode(NamedModel):
@ -35,7 +33,6 @@ class County(NamedModel):
class Meta:
app_label = 'geogapp'
required_db_features = ['gis_enabled']
def __str__(self):
return ' County, '.join([self.name, self.state])

View File

@ -21,7 +21,6 @@ from ..utils import oracle, postgis, spatialite
from .models import City, County, Zipcode
@skipUnlessDBFeature("gis_enabled")
class GeographyTest(TestCase):
fixtures = ['initial']
@ -115,7 +114,6 @@ class GeographyTest(TestCase):
self.assertEqual(rounded_value, 5439000)
@skipUnlessDBFeature("gis_enabled")
class GeographyFunctionTests(TestCase):
fixtures = ['initial']

View File

@ -10,7 +10,6 @@ ops = [
('geom', models.MultiPolygonField(srid=4326)),
],
options={
'required_db_features': ['gis_enabled'],
},
bases=(models.Model,),
),
@ -29,7 +28,6 @@ ops = [
('geom', models.PointField(srid=4326, geography=True)),
],
options={
'required_db_features': ['gis_enabled'],
},
bases=(models.Model,),
),
@ -51,7 +49,7 @@ ops = [
)
]
if connection.features.gis_enabled and connection.features.supports_raster:
if connection.features.supports_raster:
ops += [
migrations.CreateModel(
name='Heatmap',

View File

@ -2,10 +2,9 @@ from __future__ import unicode_literals
from django.core.management import call_command
from django.db import connection
from django.test import TransactionTestCase, skipUnlessDBFeature
from django.test import TransactionTestCase
@skipUnlessDBFeature("gis_enabled")
class MigrateTests(TransactionTestCase):
"""
Tests running the migrate command in Geodjango.

View File

@ -14,15 +14,13 @@ from django.test import (
from ..utils import mysql, spatialite
if connection.features.gis_enabled:
try:
GeometryColumns = connection.ops.geometry_columns()
HAS_GEOMETRY_COLUMNS = True
except NotImplementedError:
HAS_GEOMETRY_COLUMNS = False
try:
GeometryColumns = connection.ops.geometry_columns()
HAS_GEOMETRY_COLUMNS = True
except NotImplementedError:
HAS_GEOMETRY_COLUMNS = False
@skipUnlessDBFeature('gis_enabled')
class OperationTestCase(TransactionTestCase):
available_apps = ['gis_tests.gis_migrations']

View File

@ -13,15 +13,9 @@ class AllOGRFields(models.Model):
geom = models.PolygonField()
point = models.PointField()
class Meta:
required_db_features = ['gis_enabled']
class Fields3D(models.Model):
point = models.PointField(dim=3)
pointg = models.PointField(dim=3, geography=True)
line = models.LineStringField(dim=3)
poly = models.PolygonField(dim=3)
class Meta:
required_db_features = ['gis_enabled']

View File

@ -20,7 +20,6 @@ if HAS_GDAL:
from .models import AllOGRFields
@skipUnlessDBFeature("gis_enabled")
class InspectDbTests(TestCase):
def test_geom_columns(self):
"""
@ -63,7 +62,6 @@ class InspectDbTests(TestCase):
self.assertIn('poly = models.GeometryField(', output)
@skipUnlessDBFeature("gis_enabled")
@modify_settings(
INSTALLED_APPS={'append': 'django.contrib.gis'},
)

View File

@ -8,7 +8,6 @@ class NamedModel(models.Model):
class Meta:
abstract = True
required_db_features = ['gis_enabled']
def __str__(self):
return self.name
@ -37,7 +36,6 @@ class City(NamedModel):
class Meta:
app_label = 'layermap'
required_db_features = ['gis_enabled']
class Interstate(NamedModel):
@ -46,7 +44,6 @@ class Interstate(NamedModel):
class Meta:
app_label = 'layermap'
required_db_features = ['gis_enabled']
# Same as `City` above, but for testing model inheritance.
@ -73,9 +70,6 @@ class ICity2(ICity1):
class Invalid(models.Model):
point = models.PointField()
class Meta:
required_db_features = ['gis_enabled']
# Mapping dictionaries for the models above.
co_mapping = {

View File

@ -10,7 +10,7 @@ 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, skipUnlessDBFeature
from django.test import TestCase, override_settings
from django.utils._os import upath
if HAS_GEOS and HAS_GDAL:
@ -38,7 +38,6 @@ NUMS = [1, 2, 1, 19, 1] # Number of polygons for each.
STATES = ['Texas', 'Texas', 'Texas', 'Hawaii', 'Colorado']
@skipUnlessDBFeature("gis_enabled")
class LayerMapTest(TestCase):
def test_init(self):
@ -335,7 +334,6 @@ class OtherRouter(object):
return True
@skipUnlessDBFeature("gis_enabled")
@override_settings(DATABASE_ROUTERS=[OtherRouter()])
class LayerMapRouterTest(TestCase):

View File

@ -8,7 +8,6 @@ class SimpleModel(models.Model):
class Meta:
abstract = True
required_db_features = ['gis_enabled']
@python_2_unicode_compatible

View File

@ -14,7 +14,6 @@ from .models import (
)
@skipUnlessDBFeature("gis_enabled")
class RelatedGeoModelTest(TestCase):
fixtures = ['initial']

View File

@ -4,12 +4,11 @@ from django.contrib.gis import forms
from django.contrib.gis.forms import BaseGeometryWidget
from django.contrib.gis.geos import GEOSGeometry
from django.forms import ValidationError
from django.test import SimpleTestCase, override_settings, skipUnlessDBFeature
from django.test import SimpleTestCase, override_settings
from django.test.utils import patch_logger
from django.utils.html import escape
@skipUnlessDBFeature("gis_enabled")
class GeometryFieldTest(SimpleTestCase):
def test_init(self):
@ -138,7 +137,6 @@ class GeometryFieldTest(SimpleTestCase):
)
@skipUnlessDBFeature("gis_enabled")
class SpecializedFieldTest(SimpleTestCase):
def setUp(self):
self.geometries = {
@ -310,7 +308,6 @@ class SpecializedFieldTest(SimpleTestCase):
self.assertFalse(GeometryForm(data={'g': invalid.wkt}).is_valid())
@skipUnlessDBFeature("gis_enabled")
class OSMWidgetTest(SimpleTestCase):
def setUp(self):
self.geometries = {
@ -351,7 +348,6 @@ class OSMWidgetTest(SimpleTestCase):
rendered)
@skipUnlessDBFeature("gis_enabled")
class GeometryWidgetTests(SimpleTestCase):
def test_get_context_attrs(self):

View File

@ -84,11 +84,12 @@ CONTRIB_TESTS_TO_APPS = {
def get_test_modules():
modules = []
discovery_paths = [
(None, RUNTESTS_DIR),
discovery_paths = [(None, RUNTESTS_DIR)]
if connection.features.gis_enabled:
# GIS tests are in nested apps
('gis_tests', os.path.join(RUNTESTS_DIR, 'gis_tests')),
]
discovery_paths.append(('gis_tests', os.path.join(RUNTESTS_DIR, 'gis_tests')))
else:
SUBDIRS_TO_SKIP.append('gis_tests')
for modpath, dirpath in discovery_paths:
for f in os.listdir(dirpath):
@ -106,6 +107,16 @@ def get_installed():
def setup(verbosity, test_labels, parallel):
# Reduce the given test labels to just the app module path.
test_labels_set = set()
for label in test_labels:
bits = label.split('.')[:1]
test_labels_set.add('.'.join(bits))
if 'gis_tests' in test_labels_set and not connection.features.gis_enabled:
print('Aborting: A GIS database backend is required to run gis_tests.')
sys.exit(1)
if verbosity >= 1:
msg = "Testing against Django installed in '%s'" % os.path.dirname(django.__file__)
max_parallel = default_test_processes() if parallel == 0 else parallel
@ -185,12 +196,6 @@ def setup(verbosity, test_labels, parallel):
# Load all the test model apps.
test_modules = get_test_modules()
# Reduce given test labels to just the app module path
test_labels_set = set()
for label in test_labels:
bits = label.split('.')[:1]
test_labels_set.add('.'.join(bits))
installed_app_names = set(get_installed())
for modpath, module_name in test_modules:
if modpath: