Django

Code

Changeset 8155

Show
Ignore:
Timestamp:
07/30/08 12:46:02 (4 months ago)
Author:
jbronn
Message:

gis: Now plays nice with the Django test suite if the spatial prerequisites aren't installed.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/models.py

    r7666 r8155  
    212212_srid_info = True 
    213213if settings.DATABASE_ENGINE == 'postgresql_psycopg2': 
    214     from django.contrib.gis.db.backend.postgis.models import GeometryColumns, SpatialRefSys 
     214    # Because the PostGIS version is checked when initializing the spatial  
     215    # backend a `ProgrammingError` will be raised if the PostGIS tables  
     216    # and functions are not installed.  We catch here so it won't be raised when  
     217    # running the Django test suite. 
     218    from psycopg2 import ProgrammingError 
     219    try: 
     220        from django.contrib.gis.db.backend.postgis.models import GeometryColumns, SpatialRefSys 
     221    except ProgrammingError: 
     222        _srid_info = False 
    215223elif settings.DATABASE_ENGINE == 'oracle': 
    216     from django.contrib.gis.db.backend.oracle.models import GeometryColumns, SpatialRefSys 
     224    # Same thing as above, except the GEOS library is attempted to be loaded for 
     225    # `BaseSpatialBackend`, and an exception will be raised during the 
     226    # Django test suite if it doesn't exist. 
     227    try: 
     228        from django.contrib.gis.db.backend.oracle.models import GeometryColumns, SpatialRefSys 
     229    except: 
     230        _srid_info = False 
    217231else: 
    218232    _srid_info = False 
  • django/branches/gis/django/contrib/gis/tests/__init__.py

    r7641 r8155  
    4545        test_suite_names.append('test_geoip') 
    4646 
    47 def suite(): 
    48     "Builds a test suite for the GIS package." 
     47def geo_suite(): 
     48    """ 
     49    Builds a test suite for the GIS package.  This is not named 
     50    `suite` so it will not interfere with the Django test suite (since 
     51    spatial database tables are required to execute these tests on 
     52    some backends). 
     53    """ 
    4954    s = TestSuite() 
    5055    for test_suite in test_suite_names: 
     
    5560def run(verbosity=1): 
    5661    "Runs the tests that do not require geographic (GEOS, GDAL, etc.) models." 
    57     TextTestRunner(verbosity=verbosity).run(suite()) 
     62    TextTestRunner(verbosity=verbosity).run(geo_suite()) 
    5863 
    5964def run_tests(module_list, verbosity=1, interactive=True): 
     
    106111    # Creating the test suite, adding the test models to INSTALLED_APPS, and 
    107112    #  adding the model test suites to our suite package. 
    108     test_suite = suite() 
     113    test_suite = geo_suite() 
    109114    for test_model in test_models: 
    110115        module_name = 'django.contrib.gis.tests.%s' % test_model