/django/contrib/gis/tests/utils.py

https://code.google.com/p/mango-py/ · Python · 26 lines · 18 code · 4 blank · 4 comment · 2 complexity · f2661dee90065d6d0430bdc892ead4c6 MD5 · raw file

  1. from django.conf import settings
  2. from django.db import DEFAULT_DB_ALIAS
  3. # function that will pass a test.
  4. def pass_test(*args): return
  5. def no_backend(test_func, backend):
  6. "Use this decorator to disable test on specified backend."
  7. if settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'].rsplit('.')[-1] == backend:
  8. return pass_test
  9. else:
  10. return test_func
  11. # Decorators to disable entire test functions for specific
  12. # spatial backends.
  13. def no_oracle(func): return no_backend(func, 'oracle')
  14. def no_postgis(func): return no_backend(func, 'postgis')
  15. def no_mysql(func): return no_backend(func, 'mysql')
  16. def no_spatialite(func): return no_backend(func, 'spatialite')
  17. # Shortcut booleans to omit only portions of tests.
  18. _default_db = settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'].rsplit('.')[-1]
  19. oracle = _default_db == 'oracle'
  20. postgis = _default_db == 'postgis'
  21. mysql = _default_db == 'mysql'
  22. spatialite = _default_db == 'spatialite'