[Zope3-checkins] CVS: Zope3/src/zope/app/services/translation/tests - __init__.py:1.2 test_gettextexportimport.py:1.2 test_messagecatalog.py:1.2 test_translationservice.py:1.2
Jim Fulton
jim@zope.com
Wed, 25 Dec 2002 09:13:55 -0500
Update of /cvs-repository/Zope3/src/zope/app/services/translation/tests
In directory cvs.zope.org:/tmp/cvs-serv15352/src/zope/app/services/translation/tests
Added Files:
__init__.py test_gettextexportimport.py test_messagecatalog.py
test_translationservice.py
Log Message:
Grand renaming:
- Renamed most files (especially python modules) to lower case.
- Moved views and interfaces into separate hierarchies within each
project, where each top-level directory under the zope package
is a separate project.
- Moved everything to src from lib/python.
lib/python will eventually go away. I need access to the cvs
repository to make this happen, however.
There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.
=== Zope3/src/zope/app/services/translation/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:54 2002
+++ Zope3/src/zope/app/services/translation/tests/__init__.py Wed Dec 25 09:13:23 2002
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.
=== Zope3/src/zope/app/services/translation/tests/test_gettextexportimport.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:54 2002
+++ Zope3/src/zope/app/services/translation/tests/test_gettextexportimport.py Wed Dec 25 09:13:23 2002
@@ -0,0 +1,108 @@
+##############################################################################
+#
+# 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 module tests the Gettext Export and Import funciotnality of the
+Translation Service.
+
+$Id$
+"""
+import unittest, time
+
+from cStringIO import StringIO
+
+from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.app.component.metaconfigure import \
+ provideService, managerHandler
+from zope.app.component.metaconfigure import handler
+
+from zope.app.services.translation.messagecatalog import \
+ MessageCatalog
+from zope.i18n.negotiator import negotiator
+from zope.interfaces.i18n import INegotiator
+from zope.interfaces.i18n import IUserPreferredLanguages
+
+from zope.app.services.translation.translationservice import \
+ TranslationService
+from zope.app.services.translation.gettextimportfilter import \
+ GettextImportFilter
+from zope.app.services.translation.gettextexportfilter import \
+ GettextExportFilter
+
+
+
+class Environment:
+
+ __implements__ = IUserPreferredLanguages
+
+ def __init__(self, langs=()):
+ self.langs = langs
+
+ def getPreferredLanguages(self):
+ return self.langs
+
+
+class TestGettextExportImport(PlacelessSetup, unittest.TestCase):
+
+
+ _data = '''msgid ""
+msgstr ""
+"Project-Id-Version: Zope 3\\n"
+"PO-Revision-Date: %s\\n"
+"Last-Translator: Zope 3 Gettext Export Filter\\n"
+"Zope-Language: de\\n"
+"Zope-Domain: default\\n"
+"MIME-Version: 1.0\\n"
+"Content-Type: text/plain; charset=UTF-8\\n"
+"Content-Transfer-Encoding: 8bit\\n"
+
+msgid "Choose"
+msgstr "Ausw\xc3\xa4hlen!"
+
+msgid "greeting"
+msgstr "hallo"
+'''
+
+ def setUp(self):
+ PlacelessSetup.setUp(self)
+ # Setup the negotiator service registry entry
+ managerHandler('defineService', 'LanguageNegotiation', INegotiator)
+ provideService('LanguageNegotiation', negotiator, 'zope.Public')
+ self._service = TranslationService('default')
+ handler('Factories', 'provideFactory', 'Message Catalog',
+ MessageCatalog)
+
+
+ def testImportExport(self):
+ service = self._service
+
+ imp = GettextImportFilter(service)
+ imp.importMessages(['default'], ['de'],
+ StringIO(self._data %'2002/02/02 02:02'))
+
+ exp = GettextExportFilter(service)
+ result = exp.exportMessages(['default'], ['de'])
+
+ dt = time.time()
+ dt = time.localtime(dt)
+ dt = time.strftime('%Y/%m/%d %H:%M', dt)
+
+ self.assertEqual(result.strip(), (self._data %dt).strip())
+
+
+def test_suite():
+ loader = unittest.TestLoader()
+ return loader.loadTestsFromTestCase(TestGettextExportImport)
+
+
+if __name__ == '__main__':
+ unittest.TextTestRunner().run(test_suite())
=== Zope3/src/zope/app/services/translation/tests/test_messagecatalog.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:54 2002
+++ Zope3/src/zope/app/services/translation/tests/test_messagecatalog.py Wed Dec 25 09:13:23 2002
@@ -0,0 +1,49 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Test the generic persistent Message Catalog.
+
+$Id$
+"""
+import unittest
+
+from zope.app.services.translation.messagecatalog import \
+ MessageCatalog
+from zope.i18n.tests.test_ireadmessagecatalog import TestIReadMessageCatalog
+from zope.i18n.tests.test_iwritemessagecatalog import TestIWriteMessageCatalog
+
+
+class MessageCatalogTest(TestIReadMessageCatalog, TestIWriteMessageCatalog):
+
+
+ def startUp(self):
+ TestIReadMessageCatalog.startUp(self)
+ TestIWriteMessageCatalog.startUp(self)
+
+
+ def _getMessageCatalog(self):
+ catalog = MessageCatalog('en', 'default')
+ catalog.setMessage('short_greeting', 'Hello!', 0)
+ catalog.setMessage('greeting', 'Hello $name, how are you?', 0)
+ return catalog
+
+ def _getUniqueIndentifier(self):
+ return ('en', 'default')
+
+
+def test_suite():
+ loader=unittest.TestLoader()
+ return loader.loadTestsFromTestCase(MessageCatalogTest)
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run(test_suite())
=== Zope3/src/zope/app/services/translation/tests/test_translationservice.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:54 2002
+++ Zope3/src/zope/app/services/translation/tests/test_translationservice.py Wed Dec 25 09:13:23 2002
@@ -0,0 +1,83 @@
+##############################################################################
+#
+# 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 module tests the regular persistent Translation Service.
+
+$Id$
+"""
+import unittest, sys
+
+from zope.app.component.metaconfigure import handler
+
+from zope.app.services.translation.translationservice import \
+ TranslationService
+from zope.app.services.translation.messagecatalog import \
+ MessageCatalog
+from zope.i18n.tests.test_ireadtranslationservice import \
+ TestIReadTranslationService
+from zope.i18n.tests.test_iwritetranslationservice import \
+ TestIWriteTranslationService
+from zope.i18n.tests.test_isynctranslationservice import \
+ TestISyncTranslationService
+
+
+class TestTranslationService(TestIReadTranslationService,
+ TestIWriteTranslationService,
+ TestISyncTranslationService):
+
+
+ def setUp(self):
+ TestISyncTranslationService.setUp(self)
+ TestIReadTranslationService.setUp(self)
+ TestIWriteTranslationService.setUp(self)
+ handler('Factories', 'provideFactory', 'Message Catalog',
+ MessageCatalog)
+
+
+ def _getTranslationService(self):
+ service = TranslationService('default')
+
+ en_catalog = MessageCatalog('en', 'default')
+ de_catalog = MessageCatalog('de', 'default')
+ # Populate the catalogs with translations of a message id
+ en_catalog.setMessage('short_greeting', 'Hello!', 10)
+ de_catalog.setMessage('short_greeting', 'Hallo!', 10)
+ # And another message id with interpolation placeholders
+ en_catalog.setMessage('greeting', 'Hello $name, how are you?', 0)
+ de_catalog.setMessage('greeting', 'Hallo $name, wie geht es Dir?', 0)
+
+ service.setObject('en-default-1', en_catalog)
+ service.setObject('de-default-1', de_catalog)
+
+ return service
+
+ def testParameterNames(self):
+ service = self._service
+ translate = service.translate
+ eq = self.assertEqual
+ raises = self.assertRaises
+ # Test that the second argument is called `msgid'
+ eq(translate('default', msgid='short_greeting', target_language='en'),
+ 'Hello!')
+ # This is what the argument used to be called
+ raises(TypeError, translate, 'default', source='short_greeting',
+ target_language='en')
+
+
+def test_suite():
+ loader = unittest.TestLoader()
+ return loader.loadTestsFromTestCase(TestTranslationService)
+
+
+if __name__ == '__main__':
+ unittest.TextTestRunner().run(test_suite())