[Zope3-checkins] CVS: Zope3/src/zope/i18n/tests - __init__.py:1.1.2.1 de-default.mo:1.1.2.1 de-default.po:1.1.2.1 en-default.mo:1.1.2.1 en-default.po:1.1.2.1 test_gettextmessagecatalog.py:1.1.2.1 test_globaltranslationservice.py:1.1.2.1 test_ireadmessagecatalog.py:1.1.2.1 test_ireadtranslationservice.py:1.1.2.1 test_isynctranslationservice.py:1.1.2.1 test_iwritemessagecatalog.py:1.1.2.1 test_iwritetranslationservice.py:1.1.2.1 test_negotiator.py:1.1.2.1 test_simpletranslationservice.py:1.1.2.1 testi18nawareobject.py:1.1.2.1 testii18naware.py:1.1.2.1
Jim Fulton
jim@zope.com
Mon, 23 Dec 2002 14:32:54 -0500
Update of /cvs-repository/Zope3/src/zope/i18n/tests
In directory cvs.zope.org:/tmp/cvs-serv19908/zope/i18n/tests
Added Files:
Tag: NameGeddon-branch
__init__.py de-default.mo de-default.po en-default.mo
en-default.po test_gettextmessagecatalog.py
test_globaltranslationservice.py test_ireadmessagecatalog.py
test_ireadtranslationservice.py
test_isynctranslationservice.py test_iwritemessagecatalog.py
test_iwritetranslationservice.py test_negotiator.py
test_simpletranslationservice.py testi18nawareobject.py
testii18naware.py
Log Message:
Initial renaming before debugging
=== Added File Zope3/src/zope/i18n/tests/__init__.py ===
#
# This file is necessary to make this directory a package.
=== Added File Zope3/src/zope/i18n/tests/de-default.mo ===
Þ• 4 L ` a j ¼ y 6 T greeting short_greeting Project-Id-Version: Zope 3
PO-Revision-Date: 2002/06/13
Last-Translator: Zope 3 contributors
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Hallo $name, wie geht es Dir? Hallo!
=== Added File Zope3/src/zope/i18n/tests/de-default.po ===
msgid ""
msgstr ""
"Project-Id-Version: Zope 3\n"
"PO-Revision-Date: 2002/06/13\n"
"Last-Translator: Zope 3 contributors\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=ISO-8859-1\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "short_greeting"
msgstr "Hallo!"
msgid "greeting"
msgstr "Hallo $name, wie geht es Dir?"
=== Added File Zope3/src/zope/i18n/tests/en-default.mo ===
Þ• 4 L ` a j ¼ y 6 P greeting short_greeting Project-Id-Version: Zope 3
PO-Revision-Date: 2002/06/13
Last-Translator: Zope 3 contributors
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Hello $name, how are you? Hello!
=== Added File Zope3/src/zope/i18n/tests/en-default.po ===
msgid ""
msgstr ""
"Project-Id-Version: Zope 3\n"
"PO-Revision-Date: 2002/06/13\n"
"Last-Translator: Zope 3 contributors\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=ISO-8859-1\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "short_greeting"
msgstr "Hello!"
msgid "greeting"
msgstr "Hello $name, how are you?"
=== Added File Zope3/src/zope/i18n/tests/test_gettextmessagecatalog.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.
#
##############################################################################
"""Test a gettext implementation of a Message Catalog.
$Id: test_gettextmessagecatalog.py,v 1.1.2.1 2002/12/23 19:32:51 jim Exp $
"""
import unittest, sys, os
from zope.i18n.gettextmessagecatalog import GettextMessageCatalog
from zope.i18n.tests.test_ireadmessagecatalog import TestIReadMessageCatalog
class GettextMessageCatalogTest(TestIReadMessageCatalog):
def _getMessageCatalog(self):
from Zope.I18n import tests
path = os.path.split(tests.__file__)[0]
self._path = os.path.join(path, 'en-default.mo')
catalog = GettextMessageCatalog('en', 'default', self._path)
return catalog
def _getUniqueIndentifier(self):
return self._path
def test_suite():
loader=unittest.TestLoader()
return loader.loadTestsFromTestCase(GettextMessageCatalogTest)
if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())
=== Added File Zope3/src/zope/i18n/tests/test_globaltranslationservice.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 module tests the regular persistent Translation Service.
$Id: test_globaltranslationservice.py,v 1.1.2.1 2002/12/23 19:32:51 jim Exp $
"""
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
def testdir():
from Zope.I18n import tests
return os.path.dirname(tests.__file__)
class TestGlobalTranslationService(TestIReadTranslationService):
def _getTranslationService(self):
service = GlobalTranslationService('default')
path = testdir()
en_catalog = GettextMessageCatalog('en', 'default',
os.path.join(path, 'en-default.mo'))
de_catalog = GettextMessageCatalog('de', 'default',
os.path.join(path, 'de-default.mo'))
service.addCatalog(en_catalog)
service.addCatalog(de_catalog)
return service
def testSimpleNoTranslate(self):
translate = self._service.translate
raises = self.assertRaises
eq = self.assertEqual
# Unset fallback translation languages
self._service.setLanguageFallbacks([])
# Test that we have at least the minimum required arguments
raises(TypeError, translate, 'Hello')
# Test that a translation in an unsupported language returns the
# original message id unchanged, if there is no fallback language
eq(translate('default', 'short_greeting', target_language='es'),
'short_greeting')
# Same test, but use the context argument instead of target_language
context = Environment()
eq(translate('default', 'short_greeting', context=context),
'short_greeting')
# Test that at least one of context or target_language is given
raises(TypeError, translate, 'short_greeting', context=None)
def testSimpleFallbackTranslation(self):
translate = self._service.translate
raises = self.assertRaises
eq = self.assertEqual
# Test that a translation in an unsupported language returns a
# translation in the fallback language (by default, English)
eq(translate('default', 'short_greeting', target_language='es'),
u'Hello!')
# Same test, but use the context argument instead of target_language
context = Environment()
eq(translate('default', 'short_greeting', context=context),
u'Hello!')
def test_suite():
loader = unittest.TestLoader()
return loader.loadTestsFromTestCase(TestGlobalTranslationService)
if __name__ == '__main__':
unittest.TextTestRunner().run(test_suite())
=== Added File Zope3/src/zope/i18n/tests/test_ireadmessagecatalog.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_ireadmessagecatalog.py,v 1.1.2.1 2002/12/23 19:32:51 jim Exp $
"""
import unittest
from zope.interface.verify import verifyObject
from zope.interfaces.i18n import IReadMessageCatalog
class TestIReadMessageCatalog(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(IReadMessageCatalog, 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_ireadtranslationservice.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_ireadtranslationservice.py,v 1.1.2.1 2002/12/23 19:32:51 jim Exp $
"""
import unittest
from zope.interface.verify import verifyObject
from zope.component.tests.placelesssetup import PlacelessSetup
from zope.app.component.metaconfigure import \
provideService, managerHandler
from zope.i18n.negotiator import negotiator
from zope.interfaces.i18n import INegotiator
from zope.interfaces.i18n import IUserPreferredLanguages
from zope.interfaces.i18n import IReadTranslationService
from zope.interfaces.i18n import IDomain
class Environment:
__implements__ = IUserPreferredLanguages
def __init__(self, langs=()):
self.langs = langs
def getPreferredLanguages(self):
return self.langs
class TestIReadTranslationService(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(IReadTranslationService, 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 testGetDomain(self):
service = self._service
domain = service.getDomain('default')
self.assertEqual(verifyObject(IDomain, domain), 1)
def testDomainTranslate(self):
service = self._service
domain = service.getDomain('default')
translate = domain.translate
eq = self.assertEqual
# target language argument
eq(translate('short_greeting', target_language='de'), 'Hallo!')
# context argument
context = Environment(('de', 'en'))
eq(translate('short_greeting', context=context), 'Hallo!')
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
=== Added File Zope3/src/zope/i18n/tests/test_isynctranslationservice.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 Synchronization Support interface.
$Id: test_isynctranslationservice.py,v 1.1.2.1 2002/12/23 19:32:51 jim Exp $
"""
import unittest
from zope.interface.verify import verifyObject
from zope.component.tests.placelesssetup import PlacelessSetup
from zope.interfaces.i18n import ISyncTranslationService
class TestISyncTranslationService(PlacelessSetup, unittest.TestCase):
foreign_messages = [
# Message that is not locally available
{'domain': 'default', 'language': 'en', 'msgid': 'test',
'msgstr': 'Test', 'mod_time': 0},
# This message is newer than the local one.
{'domain': 'default', 'language': 'de', 'msgid': 'short_greeting',
'msgstr': 'Hallo.', 'mod_time': 20},
# This message is older than the local one.
{'domain': 'default', 'language': 'en', 'msgid': 'short_greeting',
'msgstr': 'Hello', 'mod_time': 0},
# This message is up-to-date.
{'domain': 'default', 'language': 'en', 'msgid': 'greeting',
'msgstr': 'Hello $name, how are you?', 'mod_time': 0}]
local_messages = [
# This message is older than the foreign one.
{'domain': 'default', 'language': 'de', 'msgid': 'short_greeting',
'msgstr': 'Hallo!', 'mod_time': 10},
# This message is newer than the foreign one.
{'domain': 'default', 'language': 'en', 'msgid': 'short_greeting',
'msgstr': 'Hello!', 'mod_time': 10},
# This message is up-to-date.
{'domain': 'default', 'language': 'en', 'msgid': 'greeting',
'msgstr': 'Hello $name, how are you?', 'mod_time': 0},
# This message is only available locally.
{'domain': 'default', 'language': 'de', 'msgid': 'greeting',
'msgstr': 'Hallo $name, wie geht es Dir?', 'mod_time': 0},
]
# 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(ISyncTranslationService, self._service)
def testGetMessagesMapping(self):
mapping = self._service.getMessagesMapping(['default'], ['de', 'en'],
self.foreign_messages)
self.assertEqual(mapping[('test', 'default', 'en')],
(self.foreign_messages[0], None))
self.assertEqual(mapping[('short_greeting', 'default', 'de')],
(self.foreign_messages[1], self.local_messages[0]))
self.assertEqual(mapping[('short_greeting', 'default', 'en')],
(self.foreign_messages[2], self.local_messages[1]))
self.assertEqual(mapping[('greeting', 'default', 'en')],
(self.foreign_messages[3], self.local_messages[2]))
self.assertEqual(mapping[('greeting', 'default', 'de')],
(None, self.local_messages[3]))
def testSynchronize(self):
service = self._service
mapping = service.getMessagesMapping(['default'], ['de', 'en'],
self.foreign_messages)
service.synchronize(mapping)
self.assertEqual(service.getMessage('test', 'default', 'en'),
self.foreign_messages[0])
self.assertEqual(service.getMessage('short_greeting', 'default', 'de'),
self.foreign_messages[1])
self.assertEqual(service.getMessage('short_greeting', 'default', 'en'),
self.local_messages[1])
self.assertEqual(service.getMessage('greeting', 'default', 'en'),
self.local_messages[2])
self.assertEqual(service.getMessage('greeting', 'default', 'en'),
self.foreign_messages[3])
self.assertEqual(service.getMessage('greeting', 'default', 'de'),
None)
def test_suite():
return unittest.TestSuite() # Deliberatly empty
=== Added File Zope3/src/zope/i18n/tests/test_iwritemessagecatalog.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_iwritemessagecatalog.py,v 1.1.2.1 2002/12/23 19:32:51 jim Exp $
"""
import unittest
from zope.interface.verify import verifyObject
from zope.interfaces.i18n import IWriteMessageCatalog
class TestIWriteMessageCatalog(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(IWriteMessageCatalog, self._catalog)
def testGetFullMessage(self):
catalog = self._catalog
self.assertEqual(catalog.getFullMessage('short_greeting'),
{'domain': 'default',
'language': 'en',
'msgid': 'short_greeting',
'msgstr': 'Hello!',
'mod_time': 0})
def testSetMessage(self):
catalog = self._catalog
catalog.setMessage('test', 'Test', 1)
self.assertEqual(catalog.getFullMessage('test'),
{'domain': 'default',
'language': 'en',
'msgid': 'test',
'msgstr': 'Test',
'mod_time': 1})
catalog.deleteMessage('test')
def testDeleteMessage(self):
catalog = self._catalog
self.assertEqual(catalog.queryMessage('test'), None)
catalog.setMessage('test', 'Test', 1)
self.assertEqual(catalog.queryMessage('test'), 'Test')
catalog.deleteMessage('test')
self.assertEqual(catalog.queryMessage('test'), None)
def testGetMessageIds(self):
catalog = self._catalog
ids = catalog.getMessageIds()
ids.sort()
self.assertEqual(ids, ['greeting', 'short_greeting'])
def testGetMessages(self):
catalog = self._catalog
ids = catalog.getMessageIds()
ids.sort()
self.assertEqual(ids, ['greeting', 'short_greeting'])
def test_suite():
return unittest.TestSuite() # Deliberatly empty
=== Added File Zope3/src/zope/i18n/tests/test_iwritetranslationservice.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_iwritetranslationservice.py,v 1.1.2.1 2002/12/23 19:32:51 jim Exp $
"""
import unittest
from zope.interface.verify import verifyObject
from zope.component.tests.placelesssetup import PlacelessSetup
from zope.app.component.metaconfigure import \
provideService, managerHandler
from zope.i18n.negotiator import negotiator
from zope.interfaces.i18n import INegotiator
from zope.interfaces.i18n import IUserPreferredLanguages
from zope.interfaces.i18n import ITranslationService
from zope.interfaces.i18n import IDomain
class Environment:
__implements__ = IUserPreferredLanguages
def __init__(self, langs=()):
self.langs = langs
def getPreferredLanguages(self):
return self.langs
class TestIWriteTranslationService(PlacelessSetup, unittest.TestCase):
def _getTranslationService(self):
"""This should be overwritten by every clas that inherits this test.
We expect the TranslationService to contain exactly 2 languages:
de and en
"""
def setUp(self):
PlacelessSetup.setUp(self)
self._service = self._getTranslationService()
assert verifyObject(ITranslationService, self._service)
managerHandler('defineService', 'Translation',
ITranslationService)
provideService('Translation', self._service, 'Zope.Public')
# Setup the negotiator service registry entry
managerHandler('defineService', 'LanguageNegotiation', INegotiator)
provideService('LanguageNegotiation', negotiator, 'Zope.Public')
def _getDomains(self, service):
domains = service.getAllDomains()
domains.sort()
return domains
def testGetAddDeleteDomain(self):
service = self._service
service.addLanguage('de')
d = self._getDomains(service)
self.assertEqual(service.getAllDomains(), d+[])
service.addDomain('test')
self.assertEqual(service.getAllDomains(), d+['test'])
service.addDomain('test2')
self.assertEqual(service.getAllDomains(), d+['test', 'test2'])
self.assertEqual(service.getAvailableDomains('de'),
d+['test', 'test2'])
service.deleteDomain('test')
self.assertEqual(service.getAllDomains(), d+['test2'])
service.deleteDomain('test2')
self.assertEqual(service.getAllDomains(), d+[])
def _getLanguages(self, service):
languages = service.getAllLanguages()
languages.sort()
return languages
def testGetAddDeleteLanguage(self):
service = self._service
service.addDomain('test')
langs = self._getLanguages(service)
service.addLanguage('es')
self.assertEqual(self._getLanguages(service), langs+['es'])
service.addLanguage('fr')
self.assertEqual(self._getLanguages(service), langs+['es', 'fr'])
self.assertEqual(service.getAvailableLanguages('test'),
langs+['es', 'fr'])
service.deleteLanguage('es')
self.assertEqual(self._getLanguages(service), langs+['fr'])
service.deleteLanguage('fr')
self.assertEqual(self._getLanguages(service), langs)
def testAddUpdateDeleteMessage(self):
service = self._service
self.assertEqual(service.translate('test', 'greeting',
target_language='de'), 'greeting')
service.addMessage('test', 'greeting', 'Hallo!', 'de')
self.assertEqual(service.translate('test', 'greeting',
target_language='de'), 'Hallo!')
service.updateMessage('test', 'greeting', 'Hallo Ihr da!', 'de')
self.assertEqual(service.translate('test', 'greeting',
target_language='de'),
'Hallo Ihr da!')
service.deleteMessage('test', 'greeting', 'de')
self.assertEqual(service.translate('test', 'greeting',
target_language='de'), None)
def _getMessageIds(self, service, domain, filter="%"):
ids = service.getMessageIdsOfDomain(domain, filter)
ids.sort()
return ids
def testFilteredGetAllMessageIdsOfDomain(self):
service = self._service
service.addMessage('test', 'greeting', 'Greeting!', 'en')
service.addMessage('test', 'greeting2', 'Greeting 2!', 'en')
service.addMessage('test2', 'greeting3', 'Greeting 3!', 'en')
service.addMessage('test2', 'greeting4', 'Greeting 4!', 'en')
self.assertEqual(self._getMessageIds(service, 'test'),
['greeting', 'greeting2'])
self.assertEqual(self._getMessageIds(service, 'test2'),
['greeting3', 'greeting4'])
self.assertEqual(self._getMessageIds(service, 'test', 'greeting'),
['greeting', 'greeting2'])
self.assertEqual(self._getMessageIds(service, 'test', '%2'),
['greeting2'])
self.assertEqual(self._getMessageIds(service, 'test', 'gre%2'),
['greeting2'])
self.assertEqual(self._getMessageIds(service, 'test2', 'gre%'),
['greeting3', 'greeting4'])
def test_suite():
return unittest.TestSuite() # Deliberatly empty
=== Added File Zope3/src/zope/i18n/tests/test_negotiator.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.
#
##############################################################################
"""
$Id: test_negotiator.py,v 1.1.2.1 2002/12/23 19:32:51 jim Exp $
"""
import unittest, sys
from zope.i18n.negotiator import Negotiator
from zope.interfaces.i18n import IUserPreferredLanguages
from zope.component.tests.placelesssetup import PlacelessSetup
class Env:
__implements__ = IUserPreferredLanguages
def __init__(self, langs=()):
self.langs = langs
def getPreferredLanguages(self):
return self.langs
class Test(PlacelessSetup, unittest.TestCase):
def setUp(self):
PlacelessSetup.setUp(self)
self.Negotiator = Negotiator()
def test1(self):
_cases = (
(('en','de'), ('en','de','fr'), 'en'),
(('en'), ('it','de','fr'), None)
)
for user_pref_langs, obj_langs, expected in _cases:
env = Env(user_pref_langs)
self.assertEqual(self.Negotiator.getLanguage(obj_langs, env),
expected)
def test_suite():
loader = unittest.TestLoader()
return loader.loadTestsFromTestCase(Test)
if __name__ == '__main__':
unittest.TextTestRunner().run(test_suite())
=== Added File Zope3/src/zope/i18n/tests/test_simpletranslationservice.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 module tests the regular persistent Translation Service.
$Id: test_simpletranslationservice.py,v 1.1.2.1 2002/12/23 19:32:51 jim Exp $
"""
import unittest
from zope.i18n.simpletranslationservice import SimpleTranslationService
from zope.i18n.tests.test_ireadtranslationservice import TestIReadTranslationService
class TestSimpleTranslationService(TestIReadTranslationService):
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?'}
)
return service
def test_suite():
loader = unittest.TestLoader()
return loader.loadTestsFromTestCase(TestSimpleTranslationService)
if __name__ == '__main__':
unittest.TextTestRunner().run(test_suite())
=== Added File Zope3/src/zope/i18n/tests/testi18nawareobject.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 a test for the II18nAware interface.
$Id: testi18nawareobject.py,v 1.1.2.1 2002/12/23 19:32:51 jim Exp $
"""
import unittest
from zope.interface.verify import verifyObject
from zope.interfaces.i18n import II18nAware
from zope.i18n.tests.testii18naware import TestII18nAware
class I18nAwareContentObject:
__implements__ = II18nAware
def __init__(self):
self.content = {}
self.defaultLanguage = 'en'
def getContent(self, language):
return self.content[language]
def queryContent(self, language, default=None):
return self.content.get(language, default)
def setContent(self, content, language):
self.content[language] = content
############################################################
# Implementation methods for interface
# II18nAware.py
def getDefaultLanguage(self):
'See Zope.I18n.II18nAware.II18nAware'
return self.defaultLanguage
def setDefaultLanguage(self, language):
'See Zope.I18n.II18nAware.II18nAware'
self.defaultLanguage = language
def getAvailableLanguages(self):
'See Zope.I18n.II18nAware.II18nAware'
return self.content.keys()
#
############################################################
class TestI18nAwareObject(TestII18nAware):
def _createObject(self):
object = I18nAwareContentObject()
object.setContent('English', 'en')
object.setContent('Lithuanian', 'lt')
object.setContent('French', 'fr')
return object
def testSetContent(self):
self.object.setContent('German', 'de')
self.assertEqual(self.object.content['de'], 'German')
def testGetContent(self):
self.assertEqual(self.object.getContent('en'), 'English')
self.assertRaises(KeyError, self.object.getContent, 'es')
def testQueryContent(self):
self.assertEqual(self.object.queryContent('en'), 'English')
self.assertEqual(self.object.queryContent('es', 'N/A'), 'N/A')
def test_suite():
loader = unittest.TestLoader()
return loader.loadTestsFromTestCase(TestI18nAwareObject)
if __name__ == '__main__':
unittest.TextTestRunner().run(test_suite())
=== Added File Zope3/src/zope/i18n/tests/testii18naware.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 a test for the II18nAware interface.
$Id: testii18naware.py,v 1.1.2.1 2002/12/23 19:32:51 jim Exp $
"""
import unittest
from zope.interface.verify import verifyObject
from zope.interfaces.i18n import II18nAware
def sorted(list):
list.sort()
return list
class TestII18nAware(unittest.TestCase):
def setUp(self):
self.object = self._createObject()
self.object.setDefaultLanguage('fr')
def _createObject(self):
# Should create an object that has lt, en and fr as available
# languages
pass
def testGetDefaultLanguage(self):
self.assertEqual(self.object.getDefaultLanguage(), 'fr')
def testSetDefaultLanguage(self):
self.object.setDefaultLanguage('lt')
self.assertEqual(self.object.getDefaultLanguage(), 'lt')
def testGetAvailableLanguages(self):
self.assertEqual(sorted(self.object.getAvailableLanguages()), ['en', 'fr', 'lt'])
def test_suite():
return unittest.TestSuite() # Deliberatly empty