[Zope-Checkins] CVS: Zope3/lib/python/Zope/I18n/tests - testMessageCatalog.py:1.1.2.1 testTranslationService.py:1.1.2.1 testNegotiator.py:1.1.2.5
Stephan Richter
srichter@cbu.edu
Wed, 5 Jun 2002 14:48:51 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/I18n/tests
In directory cvs.zope.org:/tmp/cvs-serv4962/tests
Modified Files:
Tag: Zope-3x-branch
testNegotiator.py
Added Files:
Tag: Zope-3x-branch
testMessageCatalog.py testTranslationService.py
Log Message:
First couple things for I18n. More coming soon. Not much is working, but
Fred and Barry would like to have the luxury to look at code. I will write
the real checkin message when it is done and working.
=== Added File Zope3/lib/python/Zope/I18n/tests/testMessageCatalog.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: testMessageCatalog.py,v 1.1.2.1 2002/06/05 18:48:50 srichter Exp $
"""
import unittest, sys
from Zope.I18n.MessageCatalog import MessageCatalog
class MessageCatalogTest(unittest.TestCase):
def testConstructorAndOtherGetMethods(self):
self.assertRaises(TypeError, MessageCatalog)
msg_catalog = MessageCatalog('en')
self.assertEqual(msg_catalog.getLanguage(), 'en')
self.assertEqual(msg_catalog.getDomain(), 'global')
self.assertEqual(msg_catalog.getIdentifier(), ('en', 'global'))
msg_catalog = MessageCatalog('de', 'calendar')
self.assertEqual(msg_catalog.getLanguage(), 'de')
self.assertEqual(msg_catalog.getDomain(), 'calendar')
self.assertEqual(msg_catalog.getIdentifier(), ('de', 'calendar'))
def testSetGetAndQueryMessage(self):
msg_catalog = MessageCatalog('de')
msg_catalog.setMessage('greeting', 'Hallo mein Schatz!')
self.assertEqual(msg_catalog.getMessage('greeting'),
'Hallo mein Schatz!')
self.assertEqual(msg_catalog.queryMessage('greeting'),
'Hallo mein Schatz!')
self.assertRaises(KeyError, msg_catalog.getMessage, ('hello'))
self.assertEqual(msg_catalog.queryMessage('hello'),
'hello')
self.assertEqual(msg_catalog.queryMessage('hello', 'greeting'),
'greeting')
def test_suite():
loader=unittest.TestLoader()
return loader.loadTestsFromTestCase(MessageCatalogTest)
if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())
=== Added File Zope3/lib/python/Zope/I18n/tests/testTranslationService.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.
#
##############################################################################
import unittest, sys
from Zope.I18n.IUserPreferedLanguages import IUserPreferedLanguages
from Zope.I18n.TranslationService import TranslationService
from Zope.I18n.MessageCatalog import MessageCatalog
from types import StringType
class Environment:
__implements__ = IUserPreferedLanguages
def __init__(self, langs=()):
self.langs = langs
def getLanguages(self):
return self.langs
class TestTranslationService(unittest.TestCase):
def testInterpolation(self):
service = TranslationService()
mapping = {'name': 'Zope', 'version': '3x'}
self.assertEqual(service.interpolate('This is $name.', mapping),
'This is Zope.')
self.assertEqual(service.interpolate('This is ${name}.', mapping),
'This is Zope.')
self.assertEqual(service.interpolate(
'This is $name version $version.', mapping),
'This is Zope version 3x.')
self.assertEqual(service.interpolate(
'This is ${name} version $version.', mapping),
'This is Zope version 3x.')
self.assertEqual(service.interpolate(
'This is $name version ${version}.', mapping),
'This is Zope version 3x.')
self.assertEqual(service.interpolate(
'This is ${name} version ${version}.', mapping),
'This is Zope version 3x.')
def setUp(self):
''' '''
self._service = TranslationService('default')
en_catalog = MessageCatalog('en', 'default')
de_catalog = MessageCatalog('de', 'default')
en_catalog.setMessage('short_greeting', 'Hello!')
de_catalog.setMessage('short_greeting', 'Hallo!')
en_catalog.setMessage('greeting', 'Hello $name, how are you?')
de_catalog.setMessage('greeting', 'Hallo $name, wie geht es Dir?')
self._service.setObject('en-default-1', en_catalog)
self._service.setObject('de-default-1', de_catalog)
def testSimpleNoTranslate(self):
service = self._service
self.assertRaises(TypeError, service.translate, 'Hello')
self.assertEqual(service.translate('default', 'short_greeting',
target_language='es'),
'short_greeting')
context = Environment()
self.assertEqual(service.translate('default', 'short_greeting',
context=context),
'short_greeting')
self.assertRaises(TypeError, service.translate, 'short_greeting',
context=None)
#def testSimpleTranslate(self):
# ''' '''
# service = self._service
# self.assertEqual(service.translate('Hello',
# destination_language_tag='de'),
# 'Hallo')
#
#
#def testSequenceTranslate(self):
# ''' '''
# service = self._service
#
# self.assertEqual(list(service.translateSequence(('Hello',),
# destination_language_tag='de')),
# ['Hallo'])
#
#
#def testDynamicSequenceTranslate(self):
# ''' '''
# service = self._service
#
# self.assertEqual(list(service.translateSequence(
# ('Hello ', Var('name'), ', how are you?'),
# destination_language_tag='de', data={'name': 'Stephan'})),
# ['Hallo Stephan, wie geht es Dir?'])
#
def test_suite():
loader=unittest.TestLoader()
return loader.loadTestsFromTestCase(TestTranslationService)
if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())
=== Zope3/lib/python/Zope/I18n/tests/testNegotiator.py 1.1.2.4 => 1.1.2.5 ===
#
##############################################################################
+"""
+
+$Id$
+"""
import unittest, sys
from Zope.I18n.Negotiator import Negotiator