Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Fixed #10420 -- GeoDjango tests are run as part of Django tes…

…ts when using spatial database backends with `runtests.py`.

Backport of r15013 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15014 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b145b1263403b4981edfef8060aafcb25c4cf842 1 parent 2565b80
Justin Bronn authored December 21, 2010
13  django/contrib/gis/tests/__init__.py
@@ -19,7 +19,7 @@ def run_gis_tests(test_labels, verbosity=1, interactive=True, failfast=False, ex
19 19
     return test_runner.run_tests(test_labels, extra_tests=extra_tests)
20 20
 
21 21
 
22  
-def geo_apps(namespace=True):
  22
+def geo_apps(namespace=True, runtests=False):
23 23
     """
24 24
     Returns a list of GeoDjango test applications that reside in
25 25
     `django.contrib.gis.tests` that can be used with the current
@@ -47,14 +47,16 @@ def geo_apps(namespace=True):
47 47
 
48 48
         apps.append('layermap')
49 49
 
50  
-    if namespace:
  50
+    if runtests:
  51
+        return [('django.contrib.gis.tests', app) for app in apps]
  52
+    elif namespace:
51 53
         return ['django.contrib.gis.tests.%s' % app
52 54
                 for app in apps]
53 55
     else:
54 56
         return apps
55 57
 
56 58
 
57  
-def geodjango_suite():
  59
+def geodjango_suite(apps=True):
58 60
     """
59 61
     Returns a TestSuite consisting only of GeoDjango tests that can be run.
60 62
     """
@@ -91,8 +93,9 @@ def geodjango_suite():
91 93
         suite.addTest(test_geoip.suite())
92 94
 
93 95
     # Finally, adding the suites for each of the GeoDjango test apps.
94  
-    for app_name in geo_apps(namespace=False):
95  
-        suite.addTest(build_suite(get_app(app_name)))
  96
+    if apps:
  97
+        for app_name in geo_apps(namespace=False):
  98
+            suite.addTest(build_suite(get_app(app_name)))
96 99
 
97 100
     return suite
98 101
 
22  tests/runtests.py
@@ -30,6 +30,12 @@
30 30
     'django.contrib.admindocs',
31 31
 ]
32 32
 
  33
+def geodjango(settings):
  34
+    # All databases must have spatial backends to run GeoDjango tests.
  35
+    spatial_dbs = [name for name, db_dict in settings.DATABASES.items()
  36
+                   if db_dict['ENGINE'].startswith('django.contrib.gis')]
  37
+    return len(spatial_dbs) == len(settings.DATABASES)
  38
+
33 39
 def get_test_models():
34 40
     models = []
35 41
     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):
124 130
 
125 131
     # Load all the test model apps.
126 132
     test_labels_set = set([label.split('.')[0] for label in test_labels])
127  
-    for model_dir, model_name in get_test_models():
  133
+    test_models = get_test_models()
  134
+
  135
+    # If GeoDjango, then we'll want to add in the test applications
  136
+    # that are a part of its test suite.
  137
+    if geodjango(settings):
  138
+        from django.contrib.gis.tests import geo_apps
  139
+        test_models.extend(geo_apps(runtests=True))
  140
+
  141
+    for model_dir, model_name in test_models:
128 142
         model_label = '.'.join([model_dir, model_name])
129 143
         # if the model was named on the command line, or
130 144
         # no models were named (i.e., run all), import
@@ -162,6 +176,12 @@ def django_tests(verbosity, interactive, failfast, test_labels):
162 176
             except ValueError:
163 177
                 pass
164 178
 
  179
+    # If GeoDjango is used, add it's tests that aren't a part of
  180
+    # an application (e.g., GEOS, GDAL, Distance objects).
  181
+    if geodjango(settings):
  182
+        from django.contrib.gis.tests import geodjango_suite
  183
+        extra_tests.append(geodjango_suite(apps=False))
  184
+
165 185
     # Run the test suite, including the extra validation tests.
166 186
     from django.test.utils import get_runner
167 187
     if not hasattr(settings, 'TEST_RUNNER'):

0 notes on commit b145b12

Please sign in to comment.
Something went wrong with that request. Please try again.