diff options
author | Éric Araujo <merwok@netwok.org> | 2010-10-04 23:59:35 (GMT) |
---|---|---|
committer | Éric Araujo <merwok@netwok.org> | 2010-10-04 23:59:35 (GMT) |
commit | c17776f96e8654dc9510daf55d90987be2e4dec2 (patch) | |
tree | 4aa2c2491e6d38d8f528094d69310219982c8f23 /Lib | |
parent | 6aab8d09b1d747d61945d3197335a99bd927b376 (diff) | |
download | cpython-c17776f96e8654dc9510daf55d90987be2e4dec2.zip cpython-c17776f96e8654dc9510daf55d90987be2e4dec2.tar.gz cpython-c17776f96e8654dc9510daf55d90987be2e4dec2.tar.bz2 |
Merged revisions 85223 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r85223 | eric.araujo | 2010-10-05 01:52:37 +0200 (mar., 05 oct. 2010) | 3 lines
Fix interaction of custom translation classes and caching (#9042)
........
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/gettext.py | 2 | ||||
-rw-r--r-- | Lib/test/test_gettext.py | 31 |
2 files changed, 32 insertions, 1 deletions
diff --git a/Lib/gettext.py b/Lib/gettext.py index 8b8b510..9973535 100644 --- a/Lib/gettext.py +++ b/Lib/gettext.py @@ -471,7 +471,7 @@ def translation(domain, localedir=None, languages=None, # once. result = None for mofile in mofiles: - key = os.path.abspath(mofile) + key = (class_, os.path.abspath(mofile)) t = _translations.get(key) if t is None: with open(mofile, 'rb') as fp: diff --git a/Lib/test/test_gettext.py b/Lib/test/test_gettext.py index d60ece7..40dc61a 100644 --- a/Lib/test/test_gettext.py +++ b/Lib/test/test_gettext.py @@ -334,6 +334,37 @@ class WeirdMetadataTest(GettextBaseTest): 'John Doe <jdoe@example.com>\nJane Foobar <jfoobar@example.com>') +class DummyGNUTranslations(gettext.GNUTranslations): + def foo(self): + return 'foo' + + +class GettextCacheTestCase(GettextBaseTest): + def test_cache(self): + self.localedir = os.curdir + self.mofile = MOFILE + + self.assertEqual(len(gettext._translations), 0) + + t = gettext.translation('gettext', self.localedir) + + self.assertEqual(len(gettext._translations), 1) + + t = gettext.translation('gettext', self.localedir, + class_=DummyGNUTranslations) + + self.assertEqual(len(gettext._translations), 2) + self.assertEqual(t.__class__, DummyGNUTranslations) + + # Calling it again doesn't add to the cache + + t = gettext.translation('gettext', self.localedir, + class_=DummyGNUTranslations) + + self.assertEqual(len(gettext._translations), 2) + self.assertEqual(t.__class__, DummyGNUTranslations) + + def test_main(): test_support.run_unittest(__name__) |