Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

__init__.py 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. from __future__ import absolute_import
  2. import anyjson
  3. import atexit
  4. import os
  5. import sys
  6. from kombu.exceptions import VersionMismatch
  7. # avoid json implementation inconsistencies.
  8. try:
  9. import json # noqa
  10. anyjson.force_implementation('json')
  11. except ImportError:
  12. anyjson.force_implementation('simplejson')
  13. def teardown():
  14. # Workaround for multiprocessing bug where logging
  15. # is attempted after global already collected at shutdown.
  16. cancelled = set()
  17. try:
  18. import multiprocessing.util
  19. cancelled.add(multiprocessing.util._exit_function)
  20. except (AttributeError, ImportError):
  21. pass
  22. try:
  23. atexit._exithandlers[:] = [
  24. e for e in atexit._exithandlers if e[0] not in cancelled
  25. ]
  26. except AttributeError: # pragma: no cover
  27. pass # Py3 missing _exithandlers
  28. def find_distribution_modules(name=__name__, file=__file__):
  29. current_dist_depth = len(name.split('.')) - 1
  30. current_dist = os.path.join(os.path.dirname(file),
  31. *([os.pardir] * current_dist_depth))
  32. abs = os.path.abspath(current_dist)
  33. dist_name = os.path.basename(abs)
  34. for dirpath, dirnames, filenames in os.walk(abs):
  35. package = (dist_name + dirpath[len(abs):]).replace('/', '.')
  36. if '__init__.py' in filenames:
  37. yield package
  38. for filename in filenames:
  39. if filename.endswith('.py') and filename != '__init__.py':
  40. yield '.'.join([package, filename])[:-3]
  41. def import_all_modules(name=__name__, file=__file__, skip=[]):
  42. for module in find_distribution_modules(name, file):
  43. if module not in skip:
  44. print('preimporting %r for coverage...' % (module, ))
  45. try:
  46. __import__(module)
  47. except (ImportError, VersionMismatch, AttributeError):
  48. pass
  49. def is_in_coverage():
  50. return (os.environ.get('COVER_ALL_MODULES') or
  51. '--with-coverage3' in sys.argv)
  52. def setup_django_env():
  53. try:
  54. from django.conf import settings
  55. except ImportError:
  56. return
  57. if not settings.configured:
  58. settings.configure(
  59. DATABASES={
  60. 'default': {
  61. 'ENGINE': 'django.db.backends.sqlite3',
  62. 'NAME': ':memory:',
  63. },
  64. },
  65. DATABASE_ENGINE='sqlite3',
  66. DATABASE_NAME=':memory:',
  67. INSTALLED_APPS=('kombu.transport.django', ),
  68. )
  69. def setup():
  70. # so coverage sees all our modules.
  71. setup_django_env()
  72. if is_in_coverage():
  73. import_all_modules()