Ticket #10420: 10420.1.diff

File 10420.1.diff, 3.0 KB (added by jbronn, 14 years ago)
  • django/contrib/gis/tests/__init__.py

    diff -r 7dc2faae6336 django/contrib/gis/tests/__init__.py
    a b  
    1717    return test_runner.run_tests(test_labels, extra_tests=extra_tests)
    1818
    1919
    20 def geo_apps(namespace=True):
     20def geo_apps(namespace=True, runtests=False):
    2121    """
    2222    Returns a list of GeoDjango test applications that reside in
    2323    `django.contrib.gis.tests` that can be used with the current
     
    4545
    4646        apps.append('layermap')
    4747
    48     if namespace:
     48    if runtests:
     49        return [('django.contrib.gis.tests', app) for app in apps]
     50    elif namespace:
    4951        return ['django.contrib.gis.tests.%s' % app
    5052                for app in apps]
    5153    else:
    5254        return apps
    5355
    5456
    55 def geodjango_suite():
     57def geodjango_suite(apps=True):
    5658    """
    5759    Returns a TestSuite consisting only of GeoDjango tests that can be run.
    5860    """
     
    8991        suite.addTest(test_geoip.suite())
    9092
    9193    # Finally, adding the suites for each of the GeoDjango test apps.
    92     for app_name in geo_apps(namespace=False):
    93         suite.addTest(build_suite(get_app(app_name)))
     94    if apps:
     95        for app_name in geo_apps(namespace=False):
     96            suite.addTest(build_suite(get_app(app_name)))
    9497
    9598    return suite
    9699
  • tests/runtests.py

    diff -r 7dc2faae6336 tests/runtests.py
    a b  
    3030    'django.contrib.staticfiles',
    3131]
    3232
     33def geodjango(settings):
     34    return settings.DATABASES['default']['ENGINE'].startswith('django.contrib.gis')
     35
    3336def get_test_models():
    3437    models = []
    3538    for loc, dirpath in (MODEL_TESTS_DIR_NAME, MODEL_TEST_DIR), (REGRESSION_TESTS_DIR_NAME, REGRESSION_TEST_DIR), (CONTRIB_DIR_NAME, CONTRIB_DIR):
     
    124127
    125128    # Load all the test model apps.
    126129    test_labels_set = set([label.split('.')[0] for label in test_labels])
    127     for model_dir, model_name in get_test_models():
     130    test_models = get_test_models()
     131
     132    # If GeoDjango, then we'll want to add in the test applications
     133    # that are a part of its test suite.
     134    if geodjango(settings):
     135        from django.contrib.gis.tests import geo_apps
     136        test_models.extend(geo_apps(runtests=True))
     137
     138    for model_dir, model_name in test_models:
    128139        model_label = '.'.join([model_dir, model_name])
    129140        # if the model was named on the command line, or
    130141        # no models were named (i.e., run all), import
     
    162173            except ValueError:
    163174                pass
    164175
     176    # If GeoDjango is used, add it's tests that aren't a part of
     177    # an application (e.g., GEOS, GDAL, Distance objects).
     178    if geodjango(settings):
     179        from django.contrib.gis.tests import geodjango_suite
     180        extra_tests.append(geodjango_suite(apps=False))
     181
    165182    # Run the test suite, including the extra validation tests.
    166183    from django.test.utils import get_runner
    167184    if not hasattr(settings, 'TEST_RUNNER'):
Back to Top