Fixed #10420 -- GeoDjango tests are run as part of Django tests when using spatial database backends with `runtests.py`.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15013 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
363177ea32
commit
d66ab474f3
|
@ -17,7 +17,7 @@ def run_gis_tests(test_labels, verbosity=1, interactive=True, failfast=False, ex
|
||||||
return test_runner.run_tests(test_labels, extra_tests=extra_tests)
|
return test_runner.run_tests(test_labels, extra_tests=extra_tests)
|
||||||
|
|
||||||
|
|
||||||
def geo_apps(namespace=True):
|
def geo_apps(namespace=True, runtests=False):
|
||||||
"""
|
"""
|
||||||
Returns a list of GeoDjango test applications that reside in
|
Returns a list of GeoDjango test applications that reside in
|
||||||
`django.contrib.gis.tests` that can be used with the current
|
`django.contrib.gis.tests` that can be used with the current
|
||||||
|
@ -45,14 +45,16 @@ def geo_apps(namespace=True):
|
||||||
|
|
||||||
apps.append('layermap')
|
apps.append('layermap')
|
||||||
|
|
||||||
if namespace:
|
if runtests:
|
||||||
|
return [('django.contrib.gis.tests', app) for app in apps]
|
||||||
|
elif namespace:
|
||||||
return ['django.contrib.gis.tests.%s' % app
|
return ['django.contrib.gis.tests.%s' % app
|
||||||
for app in apps]
|
for app in apps]
|
||||||
else:
|
else:
|
||||||
return apps
|
return apps
|
||||||
|
|
||||||
|
|
||||||
def geodjango_suite():
|
def geodjango_suite(apps=True):
|
||||||
"""
|
"""
|
||||||
Returns a TestSuite consisting only of GeoDjango tests that can be run.
|
Returns a TestSuite consisting only of GeoDjango tests that can be run.
|
||||||
"""
|
"""
|
||||||
|
@ -89,8 +91,9 @@ def geodjango_suite():
|
||||||
suite.addTest(test_geoip.suite())
|
suite.addTest(test_geoip.suite())
|
||||||
|
|
||||||
# Finally, adding the suites for each of the GeoDjango test apps.
|
# Finally, adding the suites for each of the GeoDjango test apps.
|
||||||
for app_name in geo_apps(namespace=False):
|
if apps:
|
||||||
suite.addTest(build_suite(get_app(app_name)))
|
for app_name in geo_apps(namespace=False):
|
||||||
|
suite.addTest(build_suite(get_app(app_name)))
|
||||||
|
|
||||||
return suite
|
return suite
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,12 @@ ALWAYS_INSTALLED_APPS = [
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def geodjango(settings):
|
||||||
|
# All databases must have spatial backends to run GeoDjango tests.
|
||||||
|
spatial_dbs = [name for name, db_dict in settings.DATABASES.items()
|
||||||
|
if db_dict['ENGINE'].startswith('django.contrib.gis')]
|
||||||
|
return len(spatial_dbs) == len(settings.DATABASES)
|
||||||
|
|
||||||
def get_test_models():
|
def get_test_models():
|
||||||
models = []
|
models = []
|
||||||
for loc, dirpath in (MODEL_TESTS_DIR_NAME, MODEL_TEST_DIR), (REGRESSION_TESTS_DIR_NAME, REGRESSION_TEST_DIR), (CONTRIB_DIR_NAME, CONTRIB_DIR):
|
for loc, dirpath in (MODEL_TESTS_DIR_NAME, MODEL_TEST_DIR), (REGRESSION_TESTS_DIR_NAME, REGRESSION_TEST_DIR), (CONTRIB_DIR_NAME, CONTRIB_DIR):
|
||||||
|
@ -124,7 +130,15 @@ def setup(verbosity, test_labels):
|
||||||
|
|
||||||
# Load all the test model apps.
|
# Load all the test model apps.
|
||||||
test_labels_set = set([label.split('.')[0] for label in test_labels])
|
test_labels_set = set([label.split('.')[0] for label in test_labels])
|
||||||
for model_dir, model_name in get_test_models():
|
test_models = get_test_models()
|
||||||
|
|
||||||
|
# If GeoDjango, then we'll want to add in the test applications
|
||||||
|
# that are a part of its test suite.
|
||||||
|
if geodjango(settings):
|
||||||
|
from django.contrib.gis.tests import geo_apps
|
||||||
|
test_models.extend(geo_apps(runtests=True))
|
||||||
|
|
||||||
|
for model_dir, model_name in test_models:
|
||||||
model_label = '.'.join([model_dir, model_name])
|
model_label = '.'.join([model_dir, model_name])
|
||||||
# if the model was named on the command line, or
|
# if the model was named on the command line, or
|
||||||
# no models were named (i.e., run all), import
|
# no models were named (i.e., run all), import
|
||||||
|
@ -162,6 +176,12 @@ def django_tests(verbosity, interactive, failfast, test_labels):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# If GeoDjango is used, add it's tests that aren't a part of
|
||||||
|
# an application (e.g., GEOS, GDAL, Distance objects).
|
||||||
|
if geodjango(settings):
|
||||||
|
from django.contrib.gis.tests import geodjango_suite
|
||||||
|
extra_tests.append(geodjango_suite(apps=False))
|
||||||
|
|
||||||
# Run the test suite, including the extra validation tests.
|
# Run the test suite, including the extra validation tests.
|
||||||
from django.test.utils import get_runner
|
from django.test.utils import get_runner
|
||||||
if not hasattr(settings, 'TEST_RUNNER'):
|
if not hasattr(settings, 'TEST_RUNNER'):
|
||||||
|
|
Loading…
Reference in New Issue