Merge lp:~jr/bzr/i18n-unoverride-no-i18n-tests into lp:bzr

Proposed by Jonathan Riddell
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: no longer in the source branch.
Merged at revision: 6139
Proposed branch: lp:~jr/bzr/i18n-unoverride-no-i18n-tests
Merge into: lp:bzr
Diff against target: 152 lines (+43/-12)
4 files modified
bzrlib/i18n.py (+9/-5)
bzrlib/tests/__init__.py (+1/-1)
bzrlib/tests/test_i18n.py (+17/-6)
doc/developers/testing.txt (+16/-0)
To merge this branch: bzr merge lp:~jr/bzr/i18n-unoverride-no-i18n-tests
Reviewer Review Type Date Requested Status
Vincent Ladeuil Approve
Review via email: mp+75181@code.launchpad.net

Commit message

re-enable i18n for tests which need it
add i18n info to testing documentation
add some API docs to functions which miss it

Description of the change

re-enable i18n for tests which need it
add i18n info to testing documentation
add some API docs to functions which miss it

To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote :

Thanks for following up on this !

70 + self.enableI18n()
71 from bzrlib import help
72 i18n.install()
73 self.overrideAttr(i18n, '_translations', ZzzTranslations())

Since these tests are already installing a specific translation, do they really need enable18n() ? Isn't there some possible simplification across:

- i18n.installed (disable multiple installs)
- TestCase.enable18n() (restore the ability to install, err, really?)
- i18n._translations (backdoor to install anyway)

In fact, I think the tests do not care about i18n.installed no ?

review: Needs Information
Revision history for this message
Jonathan Riddell (jr) wrote :

Yes well spotted, updated.

Revision history for this message
Vincent Ladeuil (vila) wrote :

After our IRC chat, I think you're good to land !

Thanks for your work here, it's more involved than it appears and it's good to know you care about it.

review: Approve
Revision history for this message
Jonathan Riddell (jr) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bzrlib/i18n.py'
--- bzrlib/i18n.py 2011-09-13 15:34:45 +0000
+++ bzrlib/i18n.py 2011-09-14 17:21:43 +0000
@@ -26,7 +26,7 @@
26import os26import os
27import sys27import sys
2828
29_translations = _gettext.NullTranslations()29_translations = None
3030
3131
32def gettext(message):32def gettext(message):
@@ -61,6 +61,7 @@
6161
62 :returns: concatenated translated message as unicode.62 :returns: concatenated translated message as unicode.
63 """63 """
64 install()
64 paragraphs = message.split(u'\n\n')65 paragraphs = message.split(u'\n\n')
65 ugettext = _translations.ugettext66 ugettext = _translations.ugettext
66 # Be careful not to translate the empty string -- it holds the67 # Be careful not to translate the empty string -- it holds the
@@ -71,15 +72,17 @@
71def disable_i18n():72def disable_i18n():
72 """Do not allow i18n to be enabled. Useful for third party users73 """Do not allow i18n to be enabled. Useful for third party users
73 of bzrlib."""74 of bzrlib."""
74 global installed75 global _translations
75 installed = lambda: True76 _translations = _gettext.NullTranslations()
7677
7778
78def installed():79def installed():
79 return not isinstance(_translations, _gettext.NullTranslations)80 """Returns whether translations are in use or not."""
81 return _translations is not None
8082
8183
82def install(lang=None):84def install(lang=None):
85 """Enables gettext translations."""
83 global _translations86 global _translations
84 if installed():87 if installed():
85 return88 return
@@ -97,8 +100,9 @@
97100
98101
99def uninstall():102def uninstall():
103 """Disables gettext translations."""
100 global _translations104 global _translations
101 _translations = _gettext.NullTranslations()105 _translations = None
102106
103107
104def _get_locale_dir():108def _get_locale_dir():
105109
=== modified file 'bzrlib/tests/__init__.py'
--- bzrlib/tests/__init__.py 2011-09-12 18:40:02 +0000
+++ bzrlib/tests/__init__.py 2011-09-14 17:21:43 +0000
@@ -1007,7 +1007,7 @@
1007 if 'config_stats' in selftest_debug_flags:1007 if 'config_stats' in selftest_debug_flags:
1008 self._install_config_stats_hooks()1008 self._install_config_stats_hooks()
1009 # Do not use i18n for tests (unless the test reverses this)1009 # Do not use i18n for tests (unless the test reverses this)
1010 self.overrideAttr(i18n, 'installed', lambda: True)1010 i18n.disable_i18n()
10111011
1012 def debug(self):1012 def debug(self):
1013 # debug a frame up.1013 # debug a frame up.
10141014
=== modified file 'bzrlib/tests/test_i18n.py'
--- bzrlib/tests/test_i18n.py 2011-09-13 15:34:53 +0000
+++ bzrlib/tests/test_i18n.py 2011-09-14 17:21:43 +0000
@@ -97,22 +97,36 @@
9797
98class TestInstall(tests.TestCase):98class TestInstall(tests.TestCase):
9999
100 def setUp(self):
101 super(TestInstall, self).setUp()
102 # Restore a proper env to test translation installation
103 self.overrideAttr(i18n, '_translations', None)
104
100 def test_custom_languages(self):105 def test_custom_languages(self):
101 self.addCleanup(i18n.install)
102 i18n.install('nl:fy')106 i18n.install('nl:fy')
107 # Whether we found a valid tranlsation or not doesn't matter, we got
108 # one and _translations is not None anymore.
109 self.assertIsInstance(i18n._translations,
110 i18n._gettext.NullTranslations)
103111
104 def test_no_env_variables(self):112 def test_no_env_variables(self):
105 self.addCleanup(i18n.install)
106 self.overrideEnv('LANGUAGE', None)113 self.overrideEnv('LANGUAGE', None)
107 self.overrideEnv('LC_ALL', None)114 self.overrideEnv('LC_ALL', None)
108 self.overrideEnv('LC_MESSAGES', None)115 self.overrideEnv('LC_MESSAGES', None)
109 self.overrideEnv('LANG', None)116 self.overrideEnv('LANG', None)
110 i18n.install()117 i18n.install()
118 # Whether we found a valid tranlsation or not doesn't matter, we got
119 # one and _translations is not None anymore.
120 self.assertIsInstance(i18n._translations,
121 i18n._gettext.NullTranslations)
111122
112 def test_disable_i18n(self):123 def test_disable_i18n(self):
113 i18n.disable_i18n()124 i18n.disable_i18n()
114 i18n.install()125 i18n.install()
115 self.assertTrue(isinstance(i18n._translations, i18n._gettext.NullTranslations))126 # It's disabled, you can't install anything and we fallback to null
127 self.assertIsInstance(i18n._translations,
128 i18n._gettext.NullTranslations)
129
116130
117class TestTranslate(tests.TestCaseWithTransport):131class TestTranslate(tests.TestCaseWithTransport):
118132
@@ -124,7 +138,6 @@
124 """do errors get translated?"""138 """do errors get translated?"""
125 err = None139 err = None
126 tree = self.make_branch_and_tree('.')140 tree = self.make_branch_and_tree('.')
127 self.overrideAttr(i18n, '_translations', ZzzTranslations())
128 try:141 try:
129 workingtree.WorkingTree.open('./foo')142 workingtree.WorkingTree.open('./foo')
130 except errors.NotBranchError,e:143 except errors.NotBranchError,e:
@@ -135,8 +148,6 @@
135 def test_topic_help_translation(self):148 def test_topic_help_translation(self):
136 """does topic help get translated?"""149 """does topic help get translated?"""
137 from bzrlib import help150 from bzrlib import help
138 i18n.install()
139 self.overrideAttr(i18n, '_translations', ZzzTranslations())
140 from StringIO import StringIO151 from StringIO import StringIO
141 out = StringIO()152 out = StringIO()
142 help.help("authentication", out)153 help.help("authentication", out)
143154
=== modified file 'doc/developers/testing.txt'
--- doc/developers/testing.txt 2011-08-04 00:28:09 +0000
+++ doc/developers/testing.txt 2011-09-14 17:21:43 +0000
@@ -745,6 +745,22 @@
745 _test_needs_features = [features.apport]745 _test_needs_features = [features.apport]
746746
747747
748Testing translations
749-----------------------
750
751Translations are disabled by default in tests. If you want to test
752that code is translated you can use the ``ZzzTranslations`` class from
753``test_i18n``::
754
755 self.overrideAttr(i18n, '_translations', ZzzTranslations())
756
757And check the output strings look like ``u"zz\xe5{{output}}"``.
758
759To test the gettext setup and usage you override i18n.installed back
760to self.i18nInstalled and _translations to None, see
761test_i18n.TestInstall.
762
763
748Testing deprecated code764Testing deprecated code
749-----------------------765-----------------------
750766