[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: class Meta:
abstract = True abstract = True
required_db_features = ['gis_enabled']
def __str__(self): def __str__(self):
return self.name return self.name

View File

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

View File

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

View File

@ -97,7 +97,7 @@ class Geo3DLoadingHelper(object):
Polygon3D.objects.create(name='3D BBox', poly=bbox_3d) Polygon3D.objects.create(name='3D BBox', poly=bbox_3d)
@skipUnlessDBFeature("gis_enabled", "supports_3d_storage") @skipUnlessDBFeature("supports_3d_storage")
class Geo3DTest(Geo3DLoadingHelper, TestCase): class Geo3DTest(Geo3DLoadingHelper, TestCase):
""" """
Only a subset of the PostGIS routines are 3D-enabled, and this 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) 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): class Geo3DFunctionsTests(Geo3DLoadingHelper, TestCase):
def test_kml(self): def test_kml(self):
""" """

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -15,7 +15,6 @@ from ..utils import mysql, oracle, postgis, spatialite
from .models import City, Country, CountryWebMercator, State, Track from .models import City, Country, CountryWebMercator, State, Track
@skipUnlessDBFeature("gis_enabled")
class GISFunctionsTests(TestCase): class GISFunctionsTests(TestCase):
""" """
Testing functions from django/contrib/gis/db/models/functions.py. 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 from .models import City, PennsylvaniaCity, State, Truth
@skipUnlessDBFeature("gis_enabled")
class GeoRegressionTests(TestCase): class GeoRegressionTests(TestCase):
fixtures = ['initial'] fixtures = ['initial']

View File

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

View File

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

View File

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

View File

@ -10,7 +10,6 @@ class NamedModel(models.Model):
class Meta: class Meta:
abstract = True abstract = True
required_db_features = ['gis_enabled']
def __str__(self): def __str__(self):
return self.name return self.name
@ -21,7 +20,6 @@ class City(NamedModel):
class Meta: class Meta:
app_label = 'geogapp' app_label = 'geogapp'
required_db_features = ['gis_enabled']
class Zipcode(NamedModel): class Zipcode(NamedModel):
@ -35,7 +33,6 @@ class County(NamedModel):
class Meta: class Meta:
app_label = 'geogapp' app_label = 'geogapp'
required_db_features = ['gis_enabled']
def __str__(self): def __str__(self):
return ' County, '.join([self.name, self.state]) 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 from .models import City, County, Zipcode
@skipUnlessDBFeature("gis_enabled")
class GeographyTest(TestCase): class GeographyTest(TestCase):
fixtures = ['initial'] fixtures = ['initial']
@ -115,7 +114,6 @@ class GeographyTest(TestCase):
self.assertEqual(rounded_value, 5439000) self.assertEqual(rounded_value, 5439000)
@skipUnlessDBFeature("gis_enabled")
class GeographyFunctionTests(TestCase): class GeographyFunctionTests(TestCase):
fixtures = ['initial'] fixtures = ['initial']

View File

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

View File

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

View File

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

View File

@ -13,15 +13,9 @@ class AllOGRFields(models.Model):
geom = models.PolygonField() geom = models.PolygonField()
point = models.PointField() point = models.PointField()
class Meta:
required_db_features = ['gis_enabled']
class Fields3D(models.Model): class Fields3D(models.Model):
point = models.PointField(dim=3) point = models.PointField(dim=3)
pointg = models.PointField(dim=3, geography=True) pointg = models.PointField(dim=3, geography=True)
line = models.LineStringField(dim=3) line = models.LineStringField(dim=3)
poly = models.PolygonField(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 from .models import AllOGRFields
@skipUnlessDBFeature("gis_enabled")
class InspectDbTests(TestCase): class InspectDbTests(TestCase):
def test_geom_columns(self): def test_geom_columns(self):
""" """
@ -63,7 +62,6 @@ class InspectDbTests(TestCase):
self.assertIn('poly = models.GeometryField(', output) self.assertIn('poly = models.GeometryField(', output)
@skipUnlessDBFeature("gis_enabled")
@modify_settings( @modify_settings(
INSTALLED_APPS={'append': 'django.contrib.gis'}, INSTALLED_APPS={'append': 'django.contrib.gis'},
) )

View File

@ -8,7 +8,6 @@ class NamedModel(models.Model):
class Meta: class Meta:
abstract = True abstract = True
required_db_features = ['gis_enabled']
def __str__(self): def __str__(self):
return self.name return self.name
@ -37,7 +36,6 @@ class City(NamedModel):
class Meta: class Meta:
app_label = 'layermap' app_label = 'layermap'
required_db_features = ['gis_enabled']
class Interstate(NamedModel): class Interstate(NamedModel):
@ -46,7 +44,6 @@ class Interstate(NamedModel):
class Meta: class Meta:
app_label = 'layermap' app_label = 'layermap'
required_db_features = ['gis_enabled']
# Same as `City` above, but for testing model inheritance. # Same as `City` above, but for testing model inheritance.
@ -73,9 +70,6 @@ class ICity2(ICity1):
class Invalid(models.Model): class Invalid(models.Model):
point = models.PointField() point = models.PointField()
class Meta:
required_db_features = ['gis_enabled']
# Mapping dictionaries for the models above. # Mapping dictionaries for the models above.
co_mapping = { 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.gdal import HAS_GDAL
from django.contrib.gis.geos import HAS_GEOS from django.contrib.gis.geos import HAS_GEOS
from django.db import connection 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 from django.utils._os import upath
if HAS_GEOS and HAS_GDAL: 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'] STATES = ['Texas', 'Texas', 'Texas', 'Hawaii', 'Colorado']
@skipUnlessDBFeature("gis_enabled")
class LayerMapTest(TestCase): class LayerMapTest(TestCase):
def test_init(self): def test_init(self):
@ -335,7 +334,6 @@ class OtherRouter(object):
return True return True
@skipUnlessDBFeature("gis_enabled")
@override_settings(DATABASE_ROUTERS=[OtherRouter()]) @override_settings(DATABASE_ROUTERS=[OtherRouter()])
class LayerMapRouterTest(TestCase): class LayerMapRouterTest(TestCase):

View File

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

View File

@ -14,7 +14,6 @@ from .models import (
) )
@skipUnlessDBFeature("gis_enabled")
class RelatedGeoModelTest(TestCase): class RelatedGeoModelTest(TestCase):
fixtures = ['initial'] 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.forms import BaseGeometryWidget
from django.contrib.gis.geos import GEOSGeometry from django.contrib.gis.geos import GEOSGeometry
from django.forms import ValidationError 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.test.utils import patch_logger
from django.utils.html import escape from django.utils.html import escape
@skipUnlessDBFeature("gis_enabled")
class GeometryFieldTest(SimpleTestCase): class GeometryFieldTest(SimpleTestCase):
def test_init(self): def test_init(self):
@ -138,7 +137,6 @@ class GeometryFieldTest(SimpleTestCase):
) )
@skipUnlessDBFeature("gis_enabled")
class SpecializedFieldTest(SimpleTestCase): class SpecializedFieldTest(SimpleTestCase):
def setUp(self): def setUp(self):
self.geometries = { self.geometries = {
@ -310,7 +308,6 @@ class SpecializedFieldTest(SimpleTestCase):
self.assertFalse(GeometryForm(data={'g': invalid.wkt}).is_valid()) self.assertFalse(GeometryForm(data={'g': invalid.wkt}).is_valid())
@skipUnlessDBFeature("gis_enabled")
class OSMWidgetTest(SimpleTestCase): class OSMWidgetTest(SimpleTestCase):
def setUp(self): def setUp(self):
self.geometries = { self.geometries = {
@ -351,7 +348,6 @@ class OSMWidgetTest(SimpleTestCase):
rendered) rendered)
@skipUnlessDBFeature("gis_enabled")
class GeometryWidgetTests(SimpleTestCase): class GeometryWidgetTests(SimpleTestCase):
def test_get_context_attrs(self): def test_get_context_attrs(self):

View File

@ -84,11 +84,12 @@ CONTRIB_TESTS_TO_APPS = {
def get_test_modules(): def get_test_modules():
modules = [] modules = []
discovery_paths = [ discovery_paths = [(None, RUNTESTS_DIR)]
(None, RUNTESTS_DIR), if connection.features.gis_enabled:
# GIS tests are in nested apps # 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 modpath, dirpath in discovery_paths:
for f in os.listdir(dirpath): for f in os.listdir(dirpath):
@ -106,6 +107,16 @@ def get_installed():
def setup(verbosity, test_labels, parallel): 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: if verbosity >= 1:
msg = "Testing against Django installed in '%s'" % os.path.dirname(django.__file__) msg = "Testing against Django installed in '%s'" % os.path.dirname(django.__file__)
max_parallel = default_test_processes() if parallel == 0 else parallel 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. # Load all the test model apps.
test_modules = get_test_modules() 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()) installed_app_names = set(get_installed())
for modpath, module_name in test_modules: for modpath, module_name in test_modules:
if modpath: if modpath: