Example #1
0
 def test_wanted_module_item(self):
     l = default.Loader()
     self.assertTrue(l.wanted_module_item("FOO"))
     self.assertTrue(l.wanted_module_item("Foo"))
     self.assertFalse(l.wanted_module_item("_FOO"))
     self.assertFalse(l.wanted_module_item("__FOO"))
     self.assertFalse(l.wanted_module_item("foo"))
Example #2
0
 def test_wanted_module_item(self):
     l = default.Loader()
     self.assertTrue(l.wanted_module_item('FOO'))
     self.assertTrue(l.wanted_module_item('Foo'))
     self.assertFalse(l.wanted_module_item('_FOO'))
     self.assertFalse(l.wanted_module_item('__FOO'))
     self.assertFalse(l.wanted_module_item('foo'))
Example #3
0
 def test_read_configuration_importerror(self, find_module):
     default.C_WNOCONF = True
     find_module.side_effect = ImportError()
     l = default.Loader(app=self.app)
     with self.assertWarnsRegex(NotConfigured, r'make sure it exists'):
         l.read_configuration()
     default.C_WNOCONF = False
     l.read_configuration()
Example #4
0
 def test_read_configuration_importerror(self, find_module):
     default.C_WNOCONF = True
     find_module.side_effect = ImportError()
     l = default.Loader(app=self.app)
     with pytest.warns(NotConfigured):
         l.read_configuration(fail_silently=True)
     default.C_WNOCONF = False
     l.read_configuration(fail_silently=True)
Example #5
0
 def test_read_configuration_py_in_name(self, find_module):
     prev = os.environ['CELERY_CONFIG_MODULE']
     os.environ['CELERY_CONFIG_MODULE'] = 'celeryconfig.py'
     try:
         find_module.side_effect = NotAPackage()
         l = default.Loader(app=self.app)
         with self.assertRaises(NotAPackage):
             l.read_configuration()
     finally:
         os.environ['CELERY_CONFIG_MODULE'] = prev
Example #6
0
 def test_read_configuration_ImportError(self):
     sentinel = object()
     prev, os.environ['CELERY_CONFIG_MODULE'] = (
         os.environ.get('CELERY_CONFIG_MODULE', sentinel), 'daweqew.dweqw',
     )
     try:
         l = default.Loader(app=self.app)
         with self.assertRaises(ImportError):
             l.read_configuration(fail_silently=False)
         l.read_configuration(fail_silently=True)
     finally:
         if prev is not sentinel:
             os.environ['CELERY_CONFIG_MODULE'] = prev
         else:
             os.environ.pop('CELERY_CONFIG_MODULE', None)
Example #7
0
 def test_import_from_cwd(self):
     l = default.Loader(app=self.app)
     old_path = list(sys.path)
     try:
         sys.path.remove(os.getcwd())
     except ValueError:
         pass
     celery = sys.modules.pop('celery', None)
     try:
         self.assertTrue(l.import_from_cwd('celery'))
         sys.modules.pop('celery', None)
         sys.path.insert(0, os.getcwd())
         self.assertTrue(l.import_from_cwd('celery'))
     finally:
         sys.path = old_path
         sys.modules['celery'] = celery
Example #8
0
    def test_read_configuration(self):
        from types import ModuleType

        class ConfigModule(ModuleType):
            pass

        celeryconfig = ConfigModule("celeryconfig")
        celeryconfig.CELERY_IMPORTS = ("os", "sys")
        configname = os.environ.get("CELERY_CONFIG_MODULE") or "celeryconfig"

        prevconfig = sys.modules[configname]
        sys.modules[configname] = celeryconfig
        try:
            l = default.Loader()
            settings = l.read_configuration()
            self.assertTupleEqual(settings.CELERY_IMPORTS, ("os", "sys"))
            settings = l.read_configuration()
            self.assertTupleEqual(settings.CELERY_IMPORTS, ("os", "sys"))
            l.on_worker_init()
        finally:
            sys.modules[configname] = prevconfig
Example #9
0
    def test_read_configuration(self):
        from types import ModuleType

        class ConfigModule(ModuleType):
            pass

        celeryconfig = ConfigModule('celeryconfig')
        celeryconfig.CELERY_IMPORTS = ('os', 'sys')
        configname = os.environ.get('CELERY_CONFIG_MODULE') or 'celeryconfig'

        prevconfig = sys.modules.get(configname)
        sys.modules[configname] = celeryconfig
        try:
            l = default.Loader(app=self.app)
            settings = l.read_configuration()
            self.assertTupleEqual(settings.CELERY_IMPORTS, ('os', 'sys'))
            settings = l.read_configuration()
            self.assertTupleEqual(settings.CELERY_IMPORTS, ('os', 'sys'))
            l.on_worker_init()
        finally:
            if prevconfig:
                sys.modules[configname] = prevconfig
Example #10
0
    def test_read_configuration(self):
        from types import ModuleType

        class ConfigModule(ModuleType):
            pass

        configname = os.environ.get('CELERY_CONFIG_MODULE') or 'celeryconfig'
        celeryconfig = ConfigModule(bytes_if_py2(configname))
        celeryconfig.imports = ('os', 'sys')

        prevconfig = sys.modules.get(configname)
        sys.modules[configname] = celeryconfig
        try:
            l = default.Loader(app=self.app)
            l.find_module = Mock(name='find_module')
            settings = l.read_configuration(fail_silently=False)
            assert settings.imports == ('os', 'sys')
            settings = l.read_configuration(fail_silently=False)
            assert settings.imports == ('os', 'sys')
            l.on_worker_init()
        finally:
            if prevconfig:
                sys.modules[configname] = prevconfig
Example #11
0
 def test_read_configuration_not_a_package(self, find_module):
     find_module.side_effect = NotAPackage()
     l = default.Loader(app=self.app)
     with self.assertRaises(NotAPackage):
         l.read_configuration()
Example #12
0
 def test_read_configuration_py_in_name(self, find_module):
     find_module.side_effect = NotAPackage()
     l = default.Loader(app=self.app)
     with self.assertRaises(NotAPackage):
         l.read_configuration(fail_silently=False)
Example #13
0
 def test_read_configuration_not_a_package(self, find_module):
     find_module.side_effect = NotAPackage()
     l = default.Loader(app=self.app)
     with pytest.raises(NotAPackage):
         l.read_configuration(fail_silently=False)
Example #14
0
 def test_read_configuration_importerror(self, find_module):
     find_module.side_effect = ImportError()
     l = default.Loader()
     with self.assertWarnsRegex(NotConfigured, r'make sure it exists'):
         l.read_configuration()