示例#1
0
 def test_change_lazy(self):
     _lazy.enable_lazy(True)
     tf = _factory.TranslatorFactory('domain')
     r = tf.primary('some text')
     self.assertIsInstance(r, _message.Message)
     _lazy.enable_lazy(False)
     r = tf.primary('some text')
     self.assertNotIsInstance(r, _message.Message)
示例#2
0
 def test_change_lazy(self):
     _lazy.enable_lazy(True)
     tf = _factory.TranslatorFactory('domain')
     r = tf.primary('some text')
     self.assertIsInstance(r, _message.Message)
     _lazy.enable_lazy(False)
     r = tf.primary('some text')
     self.assertNotIsInstance(r, _message.Message)
示例#3
0
 def test_change_lazy(self):
     _lazy.enable_lazy(True)
     tf = _factory.TranslatorFactory('domain')
     r = tf.primary('some text')
     self.assertIsInstance(r, _message.Message)
     _lazy.enable_lazy(False)
     r = tf.primary('some text')
     # Python 2.6 doesn't have assertNotIsInstance().
     self.assertFalse(isinstance(r, _message.Message))
    def test__gettextutils_install(self):
        _gettextutils.install('blaa')
        _lazy.enable_lazy(False)
        self.assertTrue(isinstance(self.t.primary('A String'), six.text_type))

        _gettextutils.install('blaa')
        _lazy.enable_lazy(True)
        self.assertTrue(
            isinstance(self.t.primary('A Message'), _message.Message))
示例#5
0
 def test_change_lazy(self):
     _lazy.enable_lazy(True)
     tf = _factory.TranslatorFactory('domain')
     r = tf.primary('some text')
     self.assertIsInstance(r, _message.Message)
     _lazy.enable_lazy(False)
     r = tf.primary('some text')
     # Python 2.6 doesn't have assertNotIsInstance().
     self.assertFalse(isinstance(r, _message.Message))
示例#6
0
 def test_py3(self):
     _lazy.enable_lazy(False)
     with mock.patch.object(six, "PY3", True):
         with mock.patch("gettext.translation") as translation:
             trans = mock.Mock()
             translation.return_value = trans
             trans.ugettext.side_effect = AssertionError("should have called gettext")
             tf = _factory.TranslatorFactory("domain")
             tf.primary("some text")
             trans.gettext.assert_called_with("some text")
    def test__gettextutils_install(self):
        _gettextutils.install('blaa')
        _lazy.enable_lazy(False)
        self.assertTrue(isinstance(self.t.primary('A String'),
                                   six.text_type))

        _gettextutils.install('blaa')
        _lazy.enable_lazy(True)
        self.assertTrue(isinstance(self.t.primary('A Message'),
                                   _message.Message))
示例#8
0
 def test_py3(self):
     _lazy.enable_lazy(False)
     with mock.patch.object(six, 'PY3', True):
         with mock.patch('gettext.translation') as translation:
             trans = mock.Mock()
             translation.return_value = trans
             trans.ugettext.side_effect = AssertionError(
                 'should have called gettext')
             tf = _factory.TranslatorFactory('domain')
             tf.primary('some text')
             trans.gettext.assert_called_with('some text')
示例#9
0
 def test_plural_form_py2(self):
     _lazy.enable_lazy(False)
     with mock.patch.object(six, 'PY3', False):
         with mock.patch('gettext.translation') as translation:
             trans = mock.Mock()
             translation.return_value = trans
             trans.ngettext.side_effect = AssertionError(
                 'should have called ungettext')
             tf = _factory.TranslatorFactory('domain')
             tf.plural_form('single', 'plural', 1)
             trans.ungettext.assert_called_with('single', 'plural', 1)
示例#10
0
 def test_py2(self):
     _lazy.enable_lazy(False)
     with mock.patch.object(six, 'PY3', False):
         with mock.patch('gettext.translation') as translation:
             trans = mock.Mock()
             translation.return_value = trans
             trans.gettext.side_effect = AssertionError(
                 'should have called ugettext')
             tf = _factory.TranslatorFactory('domain')
             tf.primary('some text')
             trans.ugettext.assert_called_with('some text')
示例#11
0
 def test_plural_form_py3(self):
     _lazy.enable_lazy(False)
     with mock.patch.object(six, 'PY3', True):
         with mock.patch('gettext.translation') as translation:
             trans = mock.Mock()
             translation.return_value = trans
             trans.ungettext.side_effect = AssertionError(
                 'should have called ngettext')
             tf = _factory.TranslatorFactory('domain')
             tf.plural_form('single', 'plural', 1)
             trans.ngettext.assert_called_with(
                 'single', 'plural', 1)
示例#12
0
 def test_contextual_form_py2(self):
     _lazy.enable_lazy(False)
     with mock.patch.object(six, 'PY3', False):
         with mock.patch('gettext.translation') as translation:
             trans = mock.Mock()
             translation.return_value = trans
             trans.gettext.side_effect = AssertionError(
                 'should have called ugettext')
             trans.ugettext.return_value = "some text"
             tf = _factory.TranslatorFactory('domain')
             tf.contextual_form('context', 'some text')
             trans.ugettext.assert_called_with(
                 "%s%s%s" % ('context', CONTEXT_SEPARATOR, 'some text'))
示例#13
0
 def test_contextual_form_py2(self):
     _lazy.enable_lazy(False)
     with mock.patch.object(six, 'PY3', False):
         with mock.patch('gettext.translation') as translation:
             trans = mock.Mock()
             translation.return_value = trans
             trans.gettext.side_effect = AssertionError(
                 'should have called ugettext')
             trans.ugettext.return_value = "some text"
             tf = _factory.TranslatorFactory('domain')
             tf.contextual_form('context', 'some text')
             trans.ugettext.assert_called_with(
                 "%s%s%s" % ('context', CONTEXT_SEPARATOR, 'some text'))
示例#14
0
 def test_lazy(self):
     _lazy.enable_lazy(True)
     with mock.patch.object(_message, "Message") as msg:
         tf = _factory.TranslatorFactory("domain")
         tf.primary("some text")
         msg.assert_called_with("some text", domain="domain")
示例#15
0
 def _restore_original(self):
     _lazy.enable_lazy(self._original_value)
示例#16
0
 def setUp(self):
     super(ToggleLazy, self).setUp()
     self.addCleanup(self._restore_original)
     _lazy.enable_lazy(self._enabled)
示例#17
0
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

"""
Senlin Engine Server.
"""
from oslo_config import cfg
from oslo_i18n import _lazy
from oslo_log import log as logging
from oslo_service import service

from senlin.common import consts
from senlin.common import messaging

_lazy.enable_lazy()

LOG = logging.getLogger('senlin.engine')


def main():
    logging.register_options(cfg.CONF)
    cfg.CONF(project='senlin', prog='senlin-engine')
    logging.setup(cfg.CONF, 'senlin-engine')
    logging.set_defaults()
    messaging.setup()

    from senlin.engine import service as engine

    srv = engine.EngineService(cfg.CONF.host, consts.ENGINE_TOPIC)
    launcher = service.launch(cfg.CONF, srv,
示例#18
0
 def _restore_original(self):
     _lazy.enable_lazy(self._original_value)
示例#19
0
 def setUp(self):
     super(ToggleLazy, self).setUp()
     self.addCleanup(self._restore_original)
     _lazy.enable_lazy(self._enabled)
示例#20
0
 def test_enable_lazy(self):
     _lazy.USE_LAZY = False
     _lazy.enable_lazy()
     self.assertTrue(_lazy.USE_LAZY)
示例#21
0
 def test_enable_lazy(self):
     _lazy.USE_LAZY = False
     _lazy.enable_lazy()
     self.assertTrue(_lazy.USE_LAZY)
示例#22
0
 def test_disable_lazy(self):
     _lazy.USE_LAZY = True
     _lazy.enable_lazy(False)
     self.assertFalse(_lazy.USE_LAZY)
示例#23
0
 def test_not_lazy(self):
     _lazy.enable_lazy(False)
     with mock.patch.object(_message, 'Message') as msg:
         msg.side_effect = AssertionError('should not use Message')
         tf = _factory.TranslatorFactory('domain')
         tf.primary('some text')
示例#24
0
 def test_lazy(self):
     _lazy.enable_lazy(True)
     with mock.patch.object(_message, 'Message') as msg:
         tf = _factory.TranslatorFactory('domain')
         tf.primary('some text')
         msg.assert_called_with('some text', domain='domain')
示例#25
0
 def test_lazy(self):
     _lazy.enable_lazy(True)
     with mock.patch.object(_message, 'Message') as msg:
         tf = _factory.TranslatorFactory('domain')
         tf.primary('some text')
         msg.assert_called_with('some text', domain='domain')
示例#26
0
 def test_disable_lazy(self):
     _lazy.USE_LAZY = True
     _lazy.enable_lazy(False)
     self.assertFalse(_lazy.USE_LAZY)
示例#27
0
文件: api.py 项目: MountainWei/miper
                                   os.pardir),)
if os.path.exists(os.path.join(possible_topdir, 'miper', '__init__.py')):
    sys.path.insert(0, possible_topdir)

from oslo_config import cfg
from oslo_i18n import _lazy
from oslo_log import log as logging
from oslo_service import systemd
import six
from paste import deploy

from miper.common.i18n import _LI
from miper.common import wsgi
from miper.common import rpc

_lazy.enable_lazy()

LOG = logging.getLogger('miper.api')

if __name__ == '__main__':
    try:
        logging.register_options(cfg.CONF)
        cfg.CONF(project='miper', prog='miper-api',
                 version='0.0.2')
        logging.setup(cfg.CONF, 'miper-api')

        # messaging configuration
        rpc.set_defaults(control_exchange='miper')
        rpc.init(cfg.CONF)

        conf_file = os.path.join(possible_topdir, "etc", "api-paste.ini")
示例#28
0
 def test_not_lazy(self):
     _lazy.enable_lazy(False)
     with mock.patch.object(_message, 'Message') as msg:
         msg.side_effect = AssertionError('should not use Message')
         tf = _factory.TranslatorFactory('domain')
         tf.primary('some text')