[Zope3-checkins] CVS: Zope3/src/zope/i18n/tests - test_imessagecatalog.py:1.1 test_itranslationservice.py:1.1 test_gettextmessagecatalog.py:1.3 test_globaltranslationservice.py:1.5 test_simpletranslationservice.py:1.3 test_translator.py:1.3 test_ireadmessagecatalog.py:NONE test_ireadtranslationservice.py:NONE test_isynctranslationservice.py:NONE test_iwritemessagecatalog.py:NONE test_iwritetranslationservice.py:NONE

Barry Warsaw barry@wooz.org
Tue, 25 Mar 2003 18:25:48 -0500


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

Modified Files:
	test_gettextmessagecatalog.py test_globaltranslationservice.py 
	test_simpletranslationservice.py test_translator.py 
Added Files:
	test_imessagecatalog.py test_itranslationservice.py 
Removed Files:
	test_ireadmessagecatalog.py test_ireadtranslationservice.py 
	test_isynctranslationservice.py test_iwritemessagecatalog.py 
	test_iwritetranslationservice.py 
Log Message:
Refactored the translation service interfaces and updated all the
tests.


=== Added File Zope3/src/zope/i18n/tests/test_imessagecatalog.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""This is an 'abstract' test for the IMessageCatalog interface.

$Id: test_imessagecatalog.py,v 1.1 2003/03/25 23:25:15 bwarsaw Exp $
"""
import unittest
from zope.interface.verify import verifyObject
from zope.i18n.interfaces import IMessageCatalog


class TestIMessageCatalog(unittest.TestCase):


    # This should be overwritten by every class that inherits this test
    def _getMessageCatalog(self):
        pass

    def _getUniqueIndentifier(self):
        pass


    def setUp(self):
        self._catalog = self._getMessageCatalog()
        assert verifyObject(IMessageCatalog, self._catalog)


    def testGetMessage(self):
        catalog = self._catalog
        self.assertEqual(catalog.getMessage('short_greeting'), 'Hello!')
        self.assertRaises(KeyError, catalog.getMessage, 'foo')


    def testQueryMessage(self):
        catalog = self._catalog
        self.assertEqual(catalog.queryMessage('short_greeting'), 'Hello!')
        self.assertEqual(catalog.queryMessage('foo'), None)
        self.assertEqual(catalog.queryMessage('foo', 'bar'), 'bar')


    def testGetLanguage(self):
        catalog = self._catalog
        self.assertEqual(catalog.getLanguage(), 'en')


    def testGetDomain(self):
        catalog = self._catalog
        self.assertEqual(catalog.getDomain(), 'default')


    def testGetIdentifier(self):
        catalog = self._catalog
        self.assertEqual(catalog.getIdentifier(), self._getUniqueIndentifier())


def test_suite():
    return unittest.TestSuite() # Deliberatly empty


=== Added File Zope3/src/zope/i18n/tests/test_itranslationservice.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""This is an 'abstract' test for the ITranslationService interface.

$Id: test_itranslationservice.py,v 1.1 2003/03/25 23:25:15 bwarsaw Exp $
"""

import unittest
from zope.interface.verify import verifyObject
from zope.component.tests.placelesssetup import PlacelessSetup

# XXX Bad, can't depend on app!
from zope.app.component.metaconfigure import provideService, managerHandler
from zope.i18n.negotiator import negotiator
from zope.i18n.interfaces import INegotiator
from zope.i18n.interfaces import IUserPreferredLanguages
from zope.i18n.interfaces import ITranslationService


class Environment:

    __implements__ = IUserPreferredLanguages

    def __init__(self, langs=()):
        self.langs = langs

    def getPreferredLanguages(self):
        return self.langs



class TestITranslationService(PlacelessSetup, unittest.TestCase):

    # This should be overwritten by every clas that inherits this test
    def _getTranslationService(self):
        pass

    def setUp(self):
        PlacelessSetup.setUp(self)
        self._service = self._getTranslationService()
        assert verifyObject(ITranslationService, self._service)
        # Setup the negotiator service registry entry
        managerHandler('defineService', 'LanguageNegotiation', INegotiator)
        provideService('LanguageNegotiation', negotiator, 'zope.Public')

    # I know, I know. This is not part of the interface, but it is implemented
    # in every Translation Service, so it fits well here.
    def testInterpolation(self):
        service = self._service
        interp = service.interpolate
        eq = self.assertEqual
        mapping = {'name': 'Zope', 'version': '3x'}
        # Test simple interpolations
        eq(interp('This is $name.', mapping), 'This is Zope.')
        eq(interp('This is ${name}.', mapping), 'This is Zope.')
        # Test more than one interpolation variable
        eq(interp('This is $name version $version.', mapping),
           'This is Zope version 3x.')
        eq(interp('This is ${name} version $version.', mapping),
           'This is Zope version 3x.')
        eq(interp('This is $name version ${version}.', mapping),
           'This is Zope version 3x.')
        eq(interp('This is ${name} version ${version}.', mapping),
           'This is Zope version 3x.')
        # Test escaping the $
        eq(interp('This is $$name.', mapping), 'This is $$name.')
        eq(interp('This is $${name}.', mapping), 'This is $${name}.')

    def testSimpleTranslate(self):
        translate = self._service.translate
        eq = self.assertEqual
        # Test that a given message id is properly translated in a supported
        # language
        eq(translate('default', 'short_greeting', target_language='de'),
           'Hallo!')
        # Same test, but use the context argument
        context = Environment(('de', 'en'))
        eq(translate('default', 'short_greeting', context=context),
           'Hallo!')

    def testDynamicTranslate(self):
        translate = self._service.translate
        eq = self.assertEqual
        # Testing both translation and interpolation
        eq(translate('default', 'greeting', mapping={'name': 'Stephan'},
                     target_language='de'),
           'Hallo Stephan, wie geht es Dir?')

    def testNoTranslation(self):
        translate = self._service.translate
        eq = self.assertEqual
        # Test that an unknown message id returns None as a translation
        eq(translate('default', 'glorp_smurf_hmpf', target_language='en'),
           None)

def test_suite():
    return unittest.TestSuite() # Deliberatly empty


=== Zope3/src/zope/i18n/tests/test_gettextmessagecatalog.py 1.2 => 1.3 ===
--- Zope3/src/zope/i18n/tests/test_gettextmessagecatalog.py:1.2	Wed Dec 25 09:13:40 2002
+++ Zope3/src/zope/i18n/tests/test_gettextmessagecatalog.py	Tue Mar 25 18:25:15 2003
@@ -17,11 +17,10 @@
 """
 import unittest, sys, os
 from zope.i18n.gettextmessagecatalog import GettextMessageCatalog
-from zope.i18n.tests.test_ireadmessagecatalog import TestIReadMessageCatalog
+from zope.i18n.tests.test_imessagecatalog import TestIMessageCatalog
 
 
-class GettextMessageCatalogTest(TestIReadMessageCatalog):
-
+class GettextMessageCatalogTest(TestIMessageCatalog):
 
     def _getMessageCatalog(self):
         from zope.i18n import tests


=== Zope3/src/zope/i18n/tests/test_globaltranslationservice.py 1.4 => 1.5 ===
--- Zope3/src/zope/i18n/tests/test_globaltranslationservice.py:1.4	Tue Mar 25 15:21:28 2003
+++ Zope3/src/zope/i18n/tests/test_globaltranslationservice.py	Tue Mar 25 18:25:15 2003
@@ -18,8 +18,8 @@
 import unittest, sys, os
 from zope.i18n.globaltranslationservice import GlobalTranslationService
 from zope.i18n.gettextmessagecatalog import GettextMessageCatalog
-from zope.i18n.tests.test_ireadtranslationservice \
-     import TestIReadTranslationService, Environment
+from zope.i18n.tests.test_itranslationservice import \
+     TestITranslationService, Environment
 from zope.i18n import MessageIDFactory
 
 def testdir():
@@ -27,7 +27,7 @@
     return os.path.dirname(tests.__file__)
 
 
-class TestGlobalTranslationService(TestIReadTranslationService):
+class TestGlobalTranslationService(TestITranslationService):
 
     def _getTranslationService(self):
         service = GlobalTranslationService('default')
@@ -77,14 +77,6 @@
         msgid = MessageIDFactory('alt')('short_greeting')
         self.assertEqual(translate('default', msgid,
                                    target_language='en'),
-                         u'Hey!')
-
-    def testMessageIDTranslate_w_Domain(self):
-        translate = self._service.getDomain('default').translate
-        self.assertEqual(translate(u'short_greeting', target_language='en'),
-                         u'Hello!')
-        msgid = MessageIDFactory('alt')('short_greeting')
-        self.assertEqual(translate(msgid, target_language='en'),
                          u'Hey!')
 
 


=== Zope3/src/zope/i18n/tests/test_simpletranslationservice.py 1.2 => 1.3 ===
--- Zope3/src/zope/i18n/tests/test_simpletranslationservice.py:1.2	Wed Dec 25 09:13:40 2002
+++ Zope3/src/zope/i18n/tests/test_simpletranslationservice.py	Tue Mar 25 18:25:15 2003
@@ -17,10 +17,10 @@
 """
 import unittest
 from zope.i18n.simpletranslationservice import SimpleTranslationService
-from zope.i18n.tests.test_ireadtranslationservice import TestIReadTranslationService
+from zope.i18n.tests.test_itranslationservice import TestITranslationService
 
 
-class TestSimpleTranslationService(TestIReadTranslationService):
+class TestSimpleTranslationService(TestITranslationService):
 
     def _getTranslationService(self):
         service = SimpleTranslationService(


=== Zope3/src/zope/i18n/tests/test_translator.py 1.2 => 1.3 ===
--- Zope3/src/zope/i18n/tests/test_translator.py:1.2	Tue Mar 25 16:05:43 2003
+++ Zope3/src/zope/i18n/tests/test_translator.py	Tue Mar 25 18:25:15 2003
@@ -19,14 +19,14 @@
 import os
 import unittest
 
-from zope.i18n.globaltranslationservice import translationService
-from zope.i18n.interfaces import IReadTranslationService
+from zope.i18n.globaltranslationservice import GlobalTranslationService
+from zope.i18n.interfaces import ITranslationService
 from zope.i18n.interfaces 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 getServiceManager
+from zope.component import getService
 
 
 class TranslatorTests(unittest.TestCase, PlacelessSetup):
@@ -36,9 +36,9 @@
         # Create a global translation service, initialized with a bunch of
         # catalogs (stolen from test_globaltranslationservice.py).
         path = testdir()
-        service = translationService
         de_catalog = GettextMessageCatalog('de', 'default',
                                            os.path.join(path, 'de-default.mo'))
+        service = getService(None, 'Translation')
         service.addCatalog(de_catalog)
 
         # Create a stub ILocaleIdentity

=== Removed File Zope3/src/zope/i18n/tests/test_ireadmessagecatalog.py ===

=== Removed File Zope3/src/zope/i18n/tests/test_ireadtranslationservice.py ===

=== Removed File Zope3/src/zope/i18n/tests/test_isynctranslationservice.py ===

=== Removed File Zope3/src/zope/i18n/tests/test_iwritemessagecatalog.py ===

=== Removed File Zope3/src/zope/i18n/tests/test_iwritetranslationservice.py ===