68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
from os_doc_tools.openstack.common import gettextutils
|
|
import mock
|
|
import unittest
|
|
|
|
|
|
class TestTranslatorFactory(unittest.TestCase):
|
|
|
|
def test_make_translation_func_gets_translation(self):
|
|
domain = 'domain'
|
|
tf = gettextutils.TranslatorFactory(domain)
|
|
with mock.patch.object(gettextutils.gettext,
|
|
'translation') as mock_trans:
|
|
tf._make_translation_func()
|
|
self.assertTrue(mock_trans.called)
|
|
|
|
|
|
class TestEnableLazy(unittest.TestCase):
|
|
|
|
def test_enable_lazy(self):
|
|
self.assertFalse(gettextutils.USE_LAZY)
|
|
gettextutils.enable_lazy()
|
|
self.assertTrue(gettextutils.USE_LAZY)
|
|
|
|
|
|
class TestInstall(unittest.TestCase):
|
|
|
|
def test_install(self):
|
|
domain = 'domain'
|
|
with mock.patch.object(gettextutils,
|
|
'TranslatorFactory') as mock_tf:
|
|
with mock.patch.object(gettextutils.six,
|
|
'moves'):
|
|
gettextutils.install(domain)
|
|
self.assertTrue(mock_tf.called)
|
|
|
|
|
|
class TestTranslateArgs(unittest.TestCase):
|
|
|
|
def test_translate_args(self):
|
|
msg_id = 2
|
|
message = gettextutils.Message(msg_id)
|
|
expected = msg_id
|
|
translated = gettextutils._translate_args((message))
|
|
self.assertEqual(str(translated), str(expected))
|
|
|
|
def test_translate(self):
|
|
msg_id = 2
|
|
msg = gettextutils.Message(msg_id)
|
|
exp = msg_id
|
|
transltd = gettextutils.translate(msg)
|
|
self.assertEqual(str(transltd), str(exp))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|