[Zope3-checkins] CVS: Zope3/src/zope/i18n/tests - test_translator.py:1.4

Marius Gedminas mgedmin@codeworks.lt
Fri, 11 Apr 2003 09:42:37 -0400


Update of /cvs-repository/Zope3/src/zope/i18n/tests
In directory cvs.zope.org:/tmp/cvs-serv32330/src/zope/i18n/tests

Modified Files:
	test_translator.py 
Log Message:
Fixed the ComponentLookupError when the browser does not send a list of
accepted languages.

Added an extensive XXX comment about a possibly problematic situation with
translations to a language for which there is no Zope 3 locale found.



=== Zope3/src/zope/i18n/tests/test_translator.py 1.3 => 1.4 ===
--- Zope3/src/zope/i18n/tests/test_translator.py:1.3	Tue Mar 25 18:25:15 2003
+++ Zope3/src/zope/i18n/tests/test_translator.py	Fri Apr 11 09:42:37 2003
@@ -28,8 +28,23 @@
 from zope.app.tests.placelesssetup import PlacelessSetup
 from zope.component import getService
 
+class LocaleIdentityStub:
+    # Lie -- we're only going to implement part of the interface
+    __implements__ = ILocaleIdentity
+
+    def __init__(self, language=None):
+        self.language = language
+
+class LocaleStub:
+    # Lie -- we're only going to implement part of the interface
+    __implements__ = ILocale
+
+    def __init__(self, language=None):
+        self.id = LocaleIdentityStub(language)
+
 
 class TranslatorTests(unittest.TestCase, PlacelessSetup):
+
     def setUp(self):
         # Create all the goo for placeless services
         PlacelessSetup.setUp(self)
@@ -41,23 +56,16 @@
         service = getService(None, 'Translation')
         service.addCatalog(de_catalog)
 
-        # Create a stub ILocaleIdentity
-        class LocaleIdentityStub:
-            # Lie -- we're only going to implement part of the interface
-            __implements__ = ILocaleIdentity
-            language = 'de'
-
-        # Create a stub ILocale
-        class LocaleStub:
-            # Lie -- we're only going to implement part of the interface
-            __implements__ = ILocale
-            id = LocaleIdentityStub()
-
-        self._locale = LocaleStub()
-
     def test_translator(self):
-        translator = Translator(self._locale, 'default', None)
+        locale = LocaleStub('de')
+        translator = Translator(locale, 'default', None)
         self.assertEqual(translator.translate('short_greeting'), 'Hallo!')
+
+        # context is something that is not adaptable to IUserPreferredLanguages
+        context = object()
+        locale = LocaleStub(None)
+        translator = Translator(locale, 'default', context)
+        self.assertEqual(translator.translate('short_greeting', default=42), 42)