[Zope3-checkins] CVS: Zope3/src/zope/i18n/tests - test_negotiator.py:1.8 test_simpletranslationservice.py:1.5 test_translator.py:1.9

Stephan Richter srichter at cosmos.phy.tufts.edu
Fri Feb 27 17:25:54 EST 2004


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

Modified Files:
	test_negotiator.py test_simpletranslationservice.py 
	test_translator.py 
Log Message:
I must have been on sleep-derivation when originally writing the Translator 
code, which was horribly broken.

Fixed everything and updated the engine to do the right thing too.


=== Zope3/src/zope/i18n/tests/test_negotiator.py 1.7 => 1.8 ===
--- Zope3/src/zope/i18n/tests/test_negotiator.py:1.7	Fri Feb 27 12:48:43 2004
+++ Zope3/src/zope/i18n/tests/test_negotiator.py	Fri Feb 27 17:25:23 2004
@@ -11,7 +11,7 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""
+"""Language Negotiator tests.
 
 $Id$
 """
@@ -38,7 +38,7 @@
         super(NegotiatorTest, self).setUp()
         self.Negotiator = Negotiator()
 
-    def test1(self):
+    def test_findLanguages(self):
 
         _cases = (
             (('en','de'), ('en','de','fr'),  'en'),
@@ -49,14 +49,14 @@
 
         for user_pref_langs, obj_langs, expected in _cases:
             env = Env(user_pref_langs)
-            self.assertEqual(self.Negotiator.getLanguage(obj_langs, env),
+            self.assertEqual(self.negotiator.getLanguage(obj_langs, env),
                              expected)
 
 
 def test_suite():
-    loader = unittest.TestLoader()
-    return loader.loadTestsFromTestCase(NegotiatorTest)
-
+    return unittest.TestSuite((
+        unittest.makeSuite(NegotiatorTest),
+                           ))
 
 if __name__ == '__main__':
-    unittest.TextTestRunner().run(test_suite())
+    unittest.main(defaultTest='test_suite')


=== Zope3/src/zope/i18n/tests/test_simpletranslationservice.py 1.4 => 1.5 ===
--- Zope3/src/zope/i18n/tests/test_simpletranslationservice.py:1.4	Tue Mar 25 19:19:58 2003
+++ Zope3/src/zope/i18n/tests/test_simpletranslationservice.py	Fri Feb 27 17:25:23 2004
@@ -20,18 +20,20 @@
 from zope.i18n.tests.test_itranslationservice import TestITranslationService
 
 
+data = {
+    ('default', 'en', 'short_greeting'): 'Hello!',
+    ('default', 'de', 'short_greeting'): 'Hallo!',
+    ('default', 'en', 'greeting'): 'Hello $name, how are you?',
+    ('default', 'de', 'greeting'): 'Hallo $name, wie geht es Dir?'}
+
+
 class TestSimpleTranslationService(unittest.TestCase, TestITranslationService):
 
     def setUp(self):
         TestITranslationService.setUp(self)
 
     def _getTranslationService(self):
-        service = SimpleTranslationService(
-            {('default', 'en', 'short_greeting'): 'Hello!',
-             ('default', 'de', 'short_greeting'): 'Hallo!',
-             ('default', 'en', 'greeting'): 'Hello $name, how are you?',
-             ('default', 'de', 'greeting'): 'Hallo $name, wie geht es Dir?'}
-            )
+        service = SimpleTranslationService(data)
         return service
 
 


=== Zope3/src/zope/i18n/tests/test_translator.py 1.8 => 1.9 ===
--- Zope3/src/zope/i18n/tests/test_translator.py:1.8	Thu Feb  5 17:52:33 2004
+++ Zope3/src/zope/i18n/tests/test_translator.py	Fri Feb 27 17:25:23 2004
@@ -15,60 +15,51 @@
 
 $Id$
 """
-
 import os
 import unittest
 
-from zope.i18n.interfaces.locales import ILocaleIdentity, ILocale
-from zope.i18n.translate import Translator
-from zope.i18n.gettextmessagecatalog import GettextMessageCatalog
-from zope.i18n.tests.test_globaltranslationservice import testdir
-from zope.app.tests.placelesssetup import PlacelessSetup
-from zope.component import getService
-from zope.interface import implements
+from zope.component.tests.placelesssetup import PlacelessSetup
+from zope.component import getServiceManager
 
-class LocaleIdentityStub:
-    # Lie -- we're only going to implement part of the interface
-    implements(ILocaleIdentity)
-
-    def __init__(self, language=None):
-        self.language = language
+from zope.i18n.gettextmessagecatalog import GettextMessageCatalog
+from zope.i18n.interfaces import ITranslationService, INegotiator
+from zope.i18n.negotiator import negotiator
+from zope.i18n.simpletranslationservice import SimpleTranslationService
+from zope.i18n.tests.test_simpletranslationservice import data
+from zope.i18n.tests.test_negotiator import Env as ContextStub
+from zope.i18n.translate import Translator
 
-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 TranslatorTest(PlacelessSetup, unittest.TestCase):
 
+    def setUp(self):
+        super(TranslatorTest, self).setUp()
 
-class TranslatorTests(PlacelessSetup, unittest.TestCase):
+        sm = getServiceManager(None)
+        sm.defineService('Translation', ITranslationService)
+        sm.provideService('Translation', SimpleTranslationService(data))
 
-    def setUp(self):
-        # Create all the goo for placeless services
-        super(TranslatorTests, self).setUp()
-        # Create a global translation service, initialized with a bunch of
-        # catalogs (stolen from test_globaltranslationservice.py).
-        path = testdir()
-        de_catalog = GettextMessageCatalog('de', 'default',
-                                           os.path.join(path, 'de-default.mo'))
-        service = getService(None, 'Translation')
-        service.addCatalog(de_catalog)
+        sm.defineService('LanguageNegotiation', INegotiator)
+        sm.provideService('LanguageNegotiation', negotiator)
 
     def test_translator(self):
-        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)
+        translator = Translator('default', ContextStub(['de']))
+        self.assertEqual(translator.translate('short_greeting'),
+                         'Hallo!')
+
+        translator = Translator('default', ContextStub(['de']))
+        self.assertEqual(translator.translate('short_greeting', default=42),
+                         'Hallo!')
+
+        translator = Translator('default', ContextStub(['es']))
+        self.assertEqual(translator.translate('short_greeting', default=42),
+                         42)
 
 
-
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest(unittest.makeSuite(TranslatorTests))
-    return suite
+    return unittest.TestSuite((
+        unittest.makeSuite(TranslatorTest),
+                           ))
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')




More information about the Zope3-Checkins mailing list