示例#1
0
文件: base.py 项目: zxjly/celery
 def read_configuration(self, env='CELERY_CONFIG_MODULE'):
     try:
         custom_config = os.environ[env]
     except KeyError:
         pass
     else:
         if custom_config:
             usercfg = self._import_config_module(custom_config)
             return DictAttribute(usercfg)
示例#2
0
 def read_configuration(self):
     """Load configuration from Django settings."""
     self.configured = True
     # Default backend needs to be the database backend for backward
     # compatibility.
     backend = (getattr(settings, 'CELERY_RESULT_BACKEND', None)
                or getattr(settings, 'CELERY_BACKEND', None))
     if not backend:
         settings.CELERY_RESULT_BACKEND = 'database'
     return DictAttribute(settings)
示例#3
0
 def test_pending_configuration__django_settings(self):
     with self.Celery(broker='foo://bar', backend='foo') as app:
         app.config_from_object(DictAttribute(Bunch(
             CELERY_TASK_ALWAYS_EAGER=4,
             CELERY_TASK_DEFAULT_DELIVERY_MODE=63,
             CELERY_WORKER_AGENT='foo:Barz',
             CELERY_RESULT_SERIALIZER='pickle',
         )), namespace='CELERY')
         assert app.conf.result_serializer == 'pickle'
         assert app.conf.CELERY_RESULT_SERIALIZER == 'pickle'
         assert app.conf.task_always_eager == 4
         assert app.conf.task_default_delivery_mode == 63
         assert app.conf.worker_agent == 'foo:Barz'
         assert app.conf.broker_url == 'foo://bar'
         assert app.conf.result_backend == 'foo'
 def test_get_set_keys_values_items(self):
     x = DictAttribute(Bunch())
     x['foo'] = 'The quick brown fox'
     self.assertEqual(x['foo'], 'The quick brown fox')
     self.assertEqual(x['foo'], x.obj.foo)
     self.assertEqual(x.get('foo'), 'The quick brown fox')
     self.assertIsNone(x.get('bar'))
     with self.assertRaises(KeyError):
         x['bar']
     x.foo = 'The quick yellow fox'
     self.assertEqual(x['foo'], 'The quick yellow fox')
     self.assertIn(
         ('foo', 'The quick yellow fox'),
         list(x.items()),
     )
     self.assertIn('foo', list(x.keys()))
     self.assertIn('The quick yellow fox', list(x.values()))
示例#5
0
 def test_get_set_keys_values_items(self):
     x = DictAttribute(Bunch())
     x['foo'] = 'The quick brown fox'
     assert x['foo'] == 'The quick brown fox'
     assert x['foo'] == x.obj.foo
     assert x.get('foo') == 'The quick brown fox'
     assert x.get('bar') is None
     with pytest.raises(KeyError):
         x['bar']
     x.foo = 'The quick yellow fox'
     assert x['foo'] == 'The quick yellow fox'
     assert ('foo', 'The quick yellow fox') in list(x.items())
     assert 'foo' in list(x.keys())
     assert 'The quick yellow fox' in list(x.values())
示例#6
0
 def test_get_set_keys_values_items(self):
     x = DictAttribute(Bunch())
     x['foo'] = 'The quick brown fox'
     self.assertEqual(x['foo'], 'The quick brown fox')
     self.assertEqual(x['foo'], x.obj.foo)
     self.assertEqual(x.get('foo'), 'The quick brown fox')
     self.assertIsNone(x.get('bar'))
     with self.assertRaises(KeyError):
         x['bar']
     x.foo = 'The quick yellow fox'
     self.assertEqual(x['foo'], 'The quick yellow fox')
     self.assertIn(
         ('foo', 'The quick yellow fox'),
         list(x.items()),
     )
     self.assertIn('foo', list(x.keys()))
     self.assertIn('The quick yellow fox', list(x.values()))
示例#7
0
 def test_get_set_keys_values_items(self):
     x = DictAttribute(Bunch())
     x['foo'] = 'The quick brown fox'
     assert x['foo'] == 'The quick brown fox'
     assert x['foo'] == x.obj.foo
     assert x.get('foo') == 'The quick brown fox'
     assert x.get('bar') is None
     with pytest.raises(KeyError):
         x['bar']
     x.foo = 'The quick yellow fox'
     assert x['foo'] == 'The quick yellow fox'
     assert ('foo', 'The quick yellow fox') in list(x.items())
     assert 'foo' in list(x.keys())
     assert 'The quick yellow fox' in list(x.values())
示例#8
0
 def setup_settings(self, settingsdict):
     return DictAttribute(settingsdict)
示例#9
0
 def test_items(self):
     obj = Bunch(attr1=1)
     x = DictAttribute(obj)
     x['attr2'] = 2
     assert x['attr1'] == 1
     assert x['attr2'] == 2
示例#10
0
 def test_contains(self):
     x = DictAttribute(Bunch())
     x['foo'] = 1
     assert 'foo' in x
     assert 'bar' not in x
示例#11
0
 def test_setdefault(self):
     x = DictAttribute(Bunch())
     x.setdefault('foo', 'NEW')
     assert x['foo'] == 'NEW'
     x.setdefault('foo', 'XYZ')
     assert x['foo'] == 'NEW'
示例#12
0
 def test_setdefault(self):
     x = DictAttribute(Bunch())
     x.setdefault('foo', 'NEW')
     assert x['foo'] == 'NEW'
     x.setdefault('foo', 'XYZ')
     assert x['foo'] == 'NEW'
示例#13
0
 def test_setdefault(self):
     x = DictAttribute(Bunch())
     x.setdefault('foo', 'NEW')
     self.assertEqual(x['foo'], 'NEW')
     x.setdefault('foo', 'XYZ')
     self.assertEqual(x['foo'], 'NEW')
 def test_items(self):
     obj = Bunch(attr1=1)
     x = DictAttribute(obj)
     x['attr2'] = 2
     self.assertEqual(x['attr1'], 1)
     self.assertEqual(x['attr2'], 2)
 def test_contains(self):
     x = DictAttribute(Bunch())
     x['foo'] = 1
     self.assertIn('foo', x)
     self.assertNotIn('bar', x)
 def test_setdefault(self):
     x = DictAttribute(Bunch())
     x.setdefault('foo', 'NEW')
     self.assertEqual(x['foo'], 'NEW')
     x.setdefault('foo', 'XYZ')
     self.assertEqual(x['foo'], 'NEW')