예제 #1
0
 def setUp(self):
     super(ContextFormatterTestCase, self).setUp()
     self.config(logging_context_format_string="HAS CONTEXT "
                 "[%(request_id)s]: "
                 "%(message)s",
                 logging_default_format_string="NOCTXT: %(message)s",
                 logging_debug_format_suffix="--DBG")
     self.log = log.getLogger('')  # obtain root logger instead of 'unknown'
     self._add_handler_with_cleanup(self.log)
     self._set_log_level_with_cleanup(self.log, logging.DEBUG)
     self.trans_fixture = self.useFixture(fixture_trans.Translation())
예제 #2
0
    def test_to_utf8(self):
        self.assertEqual(encodeutils.to_utf8(b'a\xe9\xff'),        # bytes
                         b'a\xe9\xff')
        self.assertEqual(encodeutils.to_utf8(u'a\xe9\xff\u20ac'),  # Unicode
                         b'a\xc3\xa9\xc3\xbf\xe2\x82\xac')
        self.assertRaises(TypeError, encodeutils.to_utf8, 123)     # invalid

        # oslo.i18n Message objects should also be accepted for convenience.
        # It works because Message is a subclass of str. Use the
        # lazy translation to get a Message instance of oslo_i18n.
        msg = oslo_i18n_fixture.Translation().lazy("test")
        self.assertEqual(encodeutils.to_utf8(msg),
                         b'test')
예제 #3
0
 def setUp(self):
     super(ToPrimitiveTestCase, self).setUp()
     self.trans_fixture = self.useFixture(fixture.Translation())
예제 #4
0
 def test_oslo_i18n_message(self):
     # use the lazy translation to get a Message instance of oslo_i18n
     exc = oslo_i18n_fixture.Translation().lazy("test")
     self.assertEqual(encodeutils.exception_to_unicode(exc), u"test")
예제 #5
0
 def setUp(self):
     super(TranslationFixtureTest, self).setUp()
     self.trans_fixture = self.useFixture(fixture.Translation())