summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2013-04-01 02:01:00 +0100
committerMark McLoughlin <markmc@redhat.com>2013-04-03 19:12:18 -0400
commitd8b66c7c1bb28672402f2bf1e410a1ee8fc4bfb6 (patch)
tree7a8e1b2bc3aa5bb351cfe620615beb13789109ad /tests
parent05219b89b367b077a1e1f61a2767e71f7f44665a (diff)
downloadoslo-d8b66c7c1bb28672402f2bf1e410a1ee8fc4bfb6.tar.gz
oslo-d8b66c7c1bb28672402f2bf1e410a1ee8fc4bfb6.tar.xz
oslo-d8b66c7c1bb28672402f2bf1e410a1ee8fc4bfb6.zip
Add a gettextutils.install() helper function
Part of fixing bug #995287 Every top-level script in every project needs to call gettext.install() so that a _() builtin function is installed and strings are translated using the correct translation domain. However, translations are always installed in the default localedir (which is commonly '/usr/share/locale') and, in cases like devstack, may be found in a project-specific localedir. To support such a use case we should have project-specific environment variables for overriding the default value of localedir - e.g. NOVA_LOCALEDIR. Add a new gettextutils.install() helper method to make this as easy as possible for projects to get right. Change-Id: I6c8549c8ff00797c96f2dd4b0b5266d18d77aa19
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_gettext.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/unit/test_gettext.py b/tests/unit/test_gettext.py
index cedc25c..3a86782 100644
--- a/tests/unit/test_gettext.py
+++ b/tests/unit/test_gettext.py
@@ -17,7 +17,9 @@
import logging
-from openstack.common.gettextutils import _
+import mock
+
+from openstack.common import gettextutils
from tests import utils
@@ -27,4 +29,16 @@ LOG = logging.getLogger(__name__)
class GettextTest(utils.BaseTestCase):
def test_gettext_does_not_blow_up(self):
- LOG.info(_('test'))
+ LOG.info(gettextutils._('test'))
+
+ def test_gettext_install_looks_up_localedir(self):
+ with mock.patch('os.environ.get') as environ_get:
+ with mock.patch('gettext.install') as gettext_install:
+ environ_get.return_value = '/foo/bar'
+
+ gettextutils.install('blaa')
+
+ environ_get.assert_called_once_with('BLAA_LOCALEDIR')
+ gettext_install.assert_called_once_with('blaa',
+ localedir='/foo/bar',
+ unicode=True)