mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Fix interaction of custom translation classes and caching (#9042)
This commit is contained in:
parent
701761693c
commit
6108bf5ed0
3 changed files with 35 additions and 1 deletions
|
@ -335,6 +335,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():
|
||||
support.run_unittest(__name__)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue