Merge lp:~alecu/ubuntu-sso-client/fix-997326 into lp:ubuntu-sso-client

Proposed by Alejandro J. Cura
Status: Merged
Approved by: dobey
Approved revision: 1017
Merged at revision: 1015
Proposed branch: lp:~alecu/ubuntu-sso-client/fix-997326
Merge into: lp:ubuntu-sso-client
Diff against target: 209 lines (+160/-2)
4 files modified
ubuntu_sso/main/qt.py (+4/-1)
ubuntu_sso/main/tests/test_qt.py (+13/-1)
ubuntu_sso/utils/locale.py (+47/-0)
ubuntu_sso/utils/tests/test_locale.py (+96/-0)
To merge this branch: bzr merge lp:~alecu/ubuntu-sso-client/fix-997326
Reviewer Review Type Date Requested Status
dobey (community) Approve
Manuel de la Peña (community) Approve
Michał Karnicki (community) Approve
Review via email: mp+143205@code.launchpad.net

Commit message

- Use a standard LC_CTYPE locale when the LANG is turkish. (LP: #997326).

To post a comment you must log in.
Revision history for this message
Michał Karnicki (karni) :
review: Approve
Revision history for this message
Manuel de la Peña (mandel) :
review: Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :
Download full text (91.7 KiB)

The attempt to merge lp:~alecu/ubuntu-sso-client/fix-997326 into lp:ubuntu-sso-client failed. Below is the output from the failed tests.

*** Running QT test suite for ubuntu_sso ***
running build
Compiled data/qt/ssl_dialog.ui into ubuntu_sso/qt/ui/ssl_dialog_ui.py
compiled data/qt/resources.qrc into ubuntu_sso/qt/ui/resources_rc.py
Compiled data/qt/loadingoverlay.ui into ubuntu_sso/qt/ui/loadingoverlay_ui.py
Compiled data/qt/proxy_credentials_dialog.ui into ubuntu_sso/qt/ui/proxy_credentials_dialog_ui.py
Compiled data/qt/reset_password.ui into ubuntu_sso/qt/ui/reset_password_ui.py
Compiled data/qt/network_detection.ui into ubuntu_sso/qt/ui/network_detection_ui.py
Compiled data/qt/email_verification.ui into ubuntu_sso/qt/ui/email_verification_ui.py
Compiled data/qt/setup_account.ui into ubuntu_sso/qt/ui/setup_account_ui.py
Compiled data/qt/forgotten_password.ui into ubuntu_sso/qt/ui/forgotten_password_ui.py
Compiled data/qt/current_user_sign_in.ui into ubuntu_sso/qt/ui/current_user_sign_in_ui.py
Compiled data/qt/success_message.ui into ubuntu_sso/qt/ui/success_message_ui.py
Compiled data/qt/error_message.ui into ubuntu_sso/qt/ui/error_message_ui.py
running build_py
creating build
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/ubuntu_sso
copying ubuntu_sso/account.py -> build/lib.linux-x86_64-2.7/ubuntu_sso
copying ubuntu_sso/logger.py -> build/lib.linux-x86_64-2.7/ubuntu_sso
copying ubuntu_sso/__init__.py -> build/lib.linux-x86_64-2.7/ubuntu_sso
copying ubuntu_sso/credentials.py -> build/lib.linux-x86_64-2.7/ubuntu_sso
creating build/lib.linux-x86_64-2.7/ubuntu_sso/tests
copying ubuntu_sso/tests/linux.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/tests
copying ubuntu_sso/tests/__init__.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/tests
copying ubuntu_sso/tests/test_credentials.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/tests
copying ubuntu_sso/tests/test_account.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/tests
creating build/lib.linux-x86_64-2.7/ubuntu_sso/keyring
copying ubuntu_sso/keyring/linux.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring
copying ubuntu_sso/keyring/__init__.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring
copying ubuntu_sso/keyring/pykeyring.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring
creating build/lib.linux-x86_64-2.7/ubuntu_sso/keyring/tests
copying ubuntu_sso/keyring/tests/__init__.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring/tests
copying ubuntu_sso/keyring/tests/test_pykeyring.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring/tests
copying ubuntu_sso/keyring/tests/test_linux.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring/tests
copying ubuntu_sso/keyring/tests/test_common.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/keyring/tests
creating build/lib.linux-x86_64-2.7/ubuntu_sso/main
copying ubuntu_sso/main/glib.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/main
copying ubuntu_sso/main/perspective_broker.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/main
copying ubuntu_sso/main/linux.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/main
copying ubuntu_sso/main/windows.py -> build/lib.linux-x86_64-2.7/ubuntu_sso/main
copying ubuntu_sso/main/qt.py -> build/lib.linux-x86_64-2.7/...

Revision history for this message
dobey (dobey) wrote :

A couple issues found by pep8:

./ubuntu_sso/utils/locale.py:34:1: E302 expected 2 blank lines, found 1
./ubuntu_sso/utils/tests/test_locale.py:80:1: W391 blank line at end of file

Also, I am wondering why you're checking LANG for changing LC_CTYPE, instead of just checking LC_CTYPE itself, or always changing it.

And can you please be sure to update the Copyright years at the top of the files you change, if they aren't already modified to include the new year? Thanks.

review: Needs Fixing
Revision history for this message
dobey (dobey) wrote :

Also, instead of poking the environment, it's probably better to use the locale module from the Python stdlib.

1017. By Alejandro J. Cura

Do not change the LC_CTYPE if already present and non-turkish

Revision history for this message
dobey (dobey) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_sso/main/qt.py'
2--- ubuntu_sso/main/qt.py 2012-04-09 17:38:24 +0000
3+++ ubuntu_sso/main/qt.py 2013-01-15 22:06:21 +0000
4@@ -1,6 +1,6 @@
5 # -*- coding: utf-8 -*-
6 #
7-# Copyright 2012 Canonical Ltd.
8+# Copyright 2012-2013 Canonical Ltd.
9 #
10 # This program is free software: you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License version 3, as published
12@@ -38,6 +38,8 @@
13
14 from PyQt4 import QtCore
15
16+from ubuntu_sso.utils.locale import fix_turkish_locale
17+
18
19 TIMERS = set()
20
21@@ -72,6 +74,7 @@
22
23 def start_setup():
24 """Setup the env to run the service."""
25+ fix_turkish_locale()
26 # this has to be created before calling dbus.mainloop.qt.DBusQtMainLoop
27 loop = QtCore.QCoreApplication(sys.argv)
28 dbus.mainloop.qt.DBusQtMainLoop(set_as_default=True)
29
30=== modified file 'ubuntu_sso/main/tests/test_qt.py'
31--- ubuntu_sso/main/tests/test_qt.py 2012-04-09 17:38:24 +0000
32+++ ubuntu_sso/main/tests/test_qt.py 2013-01-15 22:06:21 +0000
33@@ -1,6 +1,6 @@
34 # -*- coding: utf-8 -*-
35 #
36-# Copyright 2012 Canonical Ltd.
37+# Copyright 2012-2013 Canonical Ltd.
38 #
39 # This program is free software: you can redistribute it and/or modify it
40 # under the terms of the GNU General Public License version 3, as published
41@@ -80,3 +80,15 @@
42 qt.timeout_func(0, self._set_called, 1, name="a")
43 QtCore.QCoreApplication.instance().processEvents()
44 self.assertEqual(self._called, ((1,), {"name": "a"}))
45+
46+ def test_start_setup_calls_turkish_fix(self):
47+ """The start_setup function calls the turkish fix function."""
48+ self.patch(qt.QtCore, "QCoreApplication",
49+ lambda *args, **kwargs: object())
50+ self.patch(qt.dbus.mainloop.qt, "DBusQtMainLoop",
51+ lambda **kwargs: None)
52+ called = []
53+ self.patch(qt, "fix_turkish_locale", lambda: called.append(1))
54+
55+ qt.start_setup()
56+ self.assertEqual(called, [1])
57
58=== added file 'ubuntu_sso/utils/locale.py'
59--- ubuntu_sso/utils/locale.py 1970-01-01 00:00:00 +0000
60+++ ubuntu_sso/utils/locale.py 2013-01-15 22:06:21 +0000
61@@ -0,0 +1,47 @@
62+# -*- coding: utf-8 -*-
63+#
64+# Copyright 2013 Canonical Ltd.
65+#
66+# This program is free software: you can redistribute it and/or modify it
67+# under the terms of the GNU General Public License version 3, as published
68+# by the Free Software Foundation.
69+#
70+# This program is distributed in the hope that it will be useful, but
71+# WITHOUT ANY WARRANTY; without even the implied warranties of
72+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
73+# PURPOSE. See the GNU General Public License for more details.
74+#
75+# You should have received a copy of the GNU General Public License along
76+# with this program. If not, see <http://www.gnu.org/licenses/>.
77+#
78+# In addition, as a special exception, the copyright holders give
79+# permission to link the code of portions of this program with the
80+# OpenSSL library under certain conditions as described in each
81+# individual source file, and distribute linked combinations
82+# including the two.
83+# You must obey the GNU General Public License in all respects
84+# for all of the code used other than OpenSSL. If you modify
85+# file(s) with this exception, you may extend this exception to your
86+# version of the file(s), but you are not obligated to do so. If you
87+# do not wish to do so, delete this exception statement from your
88+# version. If you delete this exception statement from all source
89+# files in the program, then also delete it here.
90+"""Utility modules related to locale."""
91+
92+import os
93+
94+# this locale is always installed in Ubuntu
95+SAFE_LOCALE = "en_US.UTF-8"
96+
97+
98+def is_turkish(locale_identifier):
99+ """Return whether the locale identifier is turkish."""
100+ return locale_identifier.startswith("tr_")
101+
102+
103+def fix_turkish_locale():
104+ """Change the LC_CTYPE when the LANG is turkish. Fixes lp:997326"""
105+ lang = os.environ.get("LANG", "")
106+ ctype = os.environ.get("LC_CTYPE", "")
107+ if (is_turkish(lang) and ctype == "") or is_turkish(ctype):
108+ os.environ["LC_CTYPE"] = SAFE_LOCALE
109
110=== added file 'ubuntu_sso/utils/tests/test_locale.py'
111--- ubuntu_sso/utils/tests/test_locale.py 1970-01-01 00:00:00 +0000
112+++ ubuntu_sso/utils/tests/test_locale.py 2013-01-15 22:06:21 +0000
113@@ -0,0 +1,96 @@
114+# -*- coding: utf-8 -*-
115+#
116+# Copyright 2013 Canonical Ltd.
117+#
118+# This program is free software: you can redistribute it and/or modify it
119+# under the terms of the GNU General Public License version 3, as published
120+# by the Free Software Foundation.
121+#
122+# This program is distributed in the hope that it will be useful, but
123+# WITHOUT ANY WARRANTY; without even the implied warranties of
124+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
125+# PURPOSE. See the GNU General Public License for more details.
126+#
127+# You should have received a copy of the GNU General Public License along
128+# with this program. If not, see <http://www.gnu.org/licenses/>.
129+#
130+# In addition, as a special exception, the copyright holders give
131+# permission to link the code of portions of this program with the
132+# OpenSSL library under certain conditions as described in each
133+# individual source file, and distribute linked combinations
134+# including the two.
135+# You must obey the GNU General Public License in all respects
136+# for all of the code used other than OpenSSL. If you modify
137+# file(s) with this exception, you may extend this exception to your
138+# version of the file(s), but you are not obligated to do so. If you
139+# do not wish to do so, delete this exception statement from your
140+# version. If you delete this exception statement from all source
141+# files in the program, then also delete it here.
142+"""Tests for the locale utilities."""
143+
144+from twisted.trial.unittest import TestCase
145+
146+from ubuntu_sso.utils import locale
147+
148+NO_VALUE = object()
149+
150+
151+class LocaleTestCase(TestCase):
152+ """Test case for functions related to locale."""
153+
154+ def setUp(self):
155+ d = super(LocaleTestCase, self).setUp()
156+ self.save_environ("LC_CTYPE")
157+ self.save_environ("LANG")
158+ return d
159+
160+ def save_environ(self, env_var_name):
161+ """Save the value of an environment variable."""
162+ old_value = locale.os.environ.get(env_var_name, NO_VALUE)
163+ self.addCleanup(self.restore_environ, env_var_name, old_value)
164+ locale.os.environ[env_var_name] = "fake_locale"
165+
166+ def restore_environ(self, env_var_name, old_value):
167+ """Restore the value of an environment variable."""
168+ if old_value is NO_VALUE:
169+ if env_var_name in locale.os.environ:
170+ del(locale.os.environ[env_var_name])
171+ else:
172+ locale.os.environ[env_var_name] = old_value
173+
174+ def test_fix_turkish_locale_when_turkish(self):
175+ """The fix_turkish_locale function skips when no locale set."""
176+ locale.os.environ["LANG"] = "tr_TR.UTF-8"
177+ del(locale.os.environ["LC_CTYPE"])
178+ locale.fix_turkish_locale()
179+ self.assertEqual(locale.os.environ["LC_CTYPE"], locale.SAFE_LOCALE)
180+
181+ def test_fix_turkish_locale_when_other(self):
182+ """The fix_turkish_locale function skips when no locale set."""
183+ locale.os.environ["LANG"] = "en_EN.UTF-8"
184+ del(locale.os.environ["LC_CTYPE"])
185+ locale.fix_turkish_locale()
186+ self.assertEqual(locale.os.environ.get("LC_CTYPE", NO_VALUE), NO_VALUE)
187+
188+ def test_fix_turkish_locale_when_LANG_unset(self):
189+ """The fix_turkish_locale function skips when no locale set."""
190+ del(locale.os.environ["LANG"])
191+ del(locale.os.environ["LC_CTYPE"])
192+ locale.fix_turkish_locale()
193+ self.assertEqual(locale.os.environ.get("LC_CTYPE", NO_VALUE), NO_VALUE)
194+
195+ def test_fix_turkish_locale_when_LC_CTYPE_not_turkish(self):
196+ """The fix is skipped if the LC_CTYPE is already non-turkish."""
197+ original = "es_ES.UTF-8"
198+ locale.os.environ["LANG"] = "tr_TR.UTF-8"
199+ locale.os.environ["LC_CTYPE"] = original
200+ locale.fix_turkish_locale()
201+ self.assertEqual(locale.os.environ.get("LC_CTYPE", NO_VALUE), original)
202+
203+ def test_fix_turkish_locale_when_LC_CTYPE_is_turkish(self):
204+ """The fix is applied if the LC_CTYPE is turkish."""
205+ locale.os.environ["LANG"] = "es_ES.UTF-8"
206+ locale.os.environ["LC_CTYPE"] = "tr_TR.UTF-8"
207+ locale.fix_turkish_locale()
208+ self.assertEqual(locale.os.environ.get("LC_CTYPE", NO_VALUE),
209+ locale.SAFE_LOCALE)

Subscribers

People subscribed via source and target branches