Merge lp:~mterry/ubuntu-sso-client/no-gettext-install into lp:ubuntu-sso-client

Proposed by Michael Terry
Status: Merged
Approved by: Roberto Alsina
Approved revision: 998
Merged at revision: 998
Proposed branch: lp:~mterry/ubuntu-sso-client/no-gettext-install
Merge into: lp:ubuntu-sso-client
Diff against target: 43 lines (+17/-4)
2 files modified
ubuntu_sso/utils/tests/test_ui.py (+13/-1)
ubuntu_sso/utils/ui.py (+4/-3)
To merge this branch: bzr merge lp:~mterry/ubuntu-sso-client/no-gettext-install
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
dobey (community) Approve
Review via email: mp+124204@code.launchpad.net

Commit message

Avoid breaking built-in _ with gettext.install, using translation instead.

Description of the change

See bug 1050061 for rationale.

To post a comment you must log in.
Revision history for this message
Michael Terry (mterry) wrote :

(btw, I wasn't sure why you use unicode=True only in Python 2, but I kept that behavior, on the assumption it was important)

Revision history for this message
dobey (dobey) wrote :

Michael, there is no unicode argument to install in Python 3 it seems, and also no ugettext, and Python 3 strings default to unicode. So to support both 2 and 3, the code needed to do that (and needs to do what you've done in the patch here).

review: Approve
Revision history for this message
Roberto Alsina (ralsina) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_sso/utils/tests/test_ui.py'
2--- ubuntu_sso/utils/tests/test_ui.py 2012-04-09 17:38:24 +0000
3+++ ubuntu_sso/utils/tests/test_ui.py 2012-09-13 13:59:31 +0000
4@@ -36,8 +36,20 @@
5 is_correct_email)
6
7
8+class GettextTestCase(TestCase):
9+ """Test that we don't override builtins with gettext."""
10+
11+ def test_import(self):
12+ """Test whether importing ui module defines _ as a builtin."""
13+ # This module is already imported above, but just to make sure, since
14+ # top imports may change over time.
15+ import ubuntu_sso.utils.ui # pylint: disable=W0612
16+ with self.assertRaises(NameError):
17+ _ # pylint: disable=W0104,E0602
18+
19+
20 class GetPasswordStrengTestCase(TestCase):
21- """Test the function that returns the strengh of a password."""
22+ """Test the function that returns the strength of a password."""
23
24 def test_too_small_password(self):
25 """Test the points given to a very small password."""
26
27=== modified file 'ubuntu_sso/utils/ui.py'
28--- ubuntu_sso/utils/ui.py 2012-09-05 17:24:55 +0000
29+++ ubuntu_sso/utils/ui.py 2012-09-13 13:59:31 +0000
30@@ -35,11 +35,12 @@
31
32 from ubuntu_sso.logger import setup_logging
33
34-INSTALL_KWARGS = {}
35+TRANSLATION = gettext.translation('ubuntu-sso-client', fallback=True)
36 if sys.version_info < (3,):
37- INSTALL_KWARGS["unicode"] = True
38+ _ = TRANSLATION.ugettext
39+else:
40+ _ = TRANSLATION.gettext
41
42-gettext.install('ubuntu-sso-client', **INSTALL_KWARGS)
43 logger = setup_logging('ubuntu_sso.utils.ui')
44
45

Subscribers

People subscribed via source and target branches