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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. from __future__ import absolute_import
  2. import logging
  3. import os
  4. import sys
  5. import warnings
  6. from importlib import import_module
  7. try:
  8. WindowsError = WindowsError # noqa
  9. except NameError:
  10. class WindowsError(Exception):
  11. pass
  12. def setup():
  13. os.environ.update(
  14. # warn if config module not found
  15. C_WNOCONF='yes',
  16. KOMBU_DISABLE_LIMIT_PROTECTION='yes',
  17. )
  18. if os.environ.get('COVER_ALL_MODULES') or '--with-coverage' in sys.argv:
  19. from warnings import catch_warnings
  20. with catch_warnings(record=True):
  21. import_all_modules()
  22. warnings.resetwarnings()
  23. from celery.tests.case import Trap
  24. from celery._state import set_default_app
  25. set_default_app(Trap())
  26. def teardown():
  27. # Don't want SUBDEBUG log messages at finalization.
  28. try:
  29. from multiprocessing.util import get_logger
  30. except ImportError:
  31. pass
  32. else:
  33. get_logger().setLevel(logging.WARNING)
  34. # Make sure test database is removed.
  35. import os
  36. if os.path.exists('test.db'):
  37. try:
  38. os.remove('test.db')
  39. except WindowsError:
  40. pass
  41. # Make sure there are no remaining threads at shutdown.
  42. import threading
  43. remaining_threads = [thread for thread in threading.enumerate()
  44. if thread.getName() != 'MainThread']
  45. if remaining_threads:
  46. sys.stderr.write(
  47. '\n\n**WARNING**: Remaining threads at teardown: %r...\n' % (
  48. remaining_threads))
  49. def find_distribution_modules(name=__name__, file=__file__):
  50. current_dist_depth = len(name.split('.')) - 1
  51. current_dist = os.path.join(os.path.dirname(file),
  52. *([os.pardir] * current_dist_depth))
  53. abs = os.path.abspath(current_dist)
  54. dist_name = os.path.basename(abs)
  55. for dirpath, dirnames, filenames in os.walk(abs):
  56. package = (dist_name + dirpath[len(abs):]).replace('/', '.')
  57. if '__init__.py' in filenames:
  58. yield package
  59. for filename in filenames:
  60. if filename.endswith('.py') and filename != '__init__.py':
  61. yield '.'.join([package, filename])[:-3]
  62. def import_all_modules(name=__name__, file=__file__,
  63. skip=('celery.decorators',
  64. 'celery.contrib.batches',
  65. 'celery.task')):
  66. for module in find_distribution_modules(name, file):
  67. if not module.startswith(skip):
  68. try:
  69. import_module(module)
  70. except ImportError:
  71. pass