[Zope3-checkins] CVS: Zope3/src/zope/i18n/tests -
test_interpolate.py:1.1 test_itranslationdomain.py:1.1
test_simpletranslationdomain.py:1.1
test_translationdomain.py:1.1 test_imessagecatalog.py:1.3
test_messageid.py:1.6 test_globaltranslationservice.py:NONE
test_itranslationservice.py:NONE
test_simpletranslationservice.py:NONE test_translator.py:NONE
Stephan Richter
srichter at cosmos.phy.tufts.edu
Mon Mar 8 18:36:02 EST 2004
Update of /cvs-repository/Zope3/src/zope/i18n/tests
In directory cvs.zope.org:/tmp/cvs-serv5256/src/zope/i18n/tests
Modified Files:
test_imessagecatalog.py test_messageid.py
Added Files:
test_interpolate.py test_itranslationdomain.py
test_simpletranslationdomain.py test_translationdomain.py
Removed Files:
test_globaltranslationservice.py test_itranslationservice.py
test_simpletranslationservice.py test_translator.py
Log Message:
Changed to use translation domains versus a translation
service. zope.i18n.__init__ provides a convenience translate() method.
=== Added File Zope3/src/zope/i18n/tests/test_interpolate.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 ITranslationDomain interface.
$Id: test_interpolate.py,v 1.1 2004/03/08 23:36:00 srichter Exp $
"""
import unittest
from zope.i18n import interpolate
class TestInterpolation(unittest.TestCase):
def testInterpolation(self):
mapping = {'name': 'Zope', 'version': '3x', 'number': 3}
# Test simple interpolations
self.assertEqual(
interpolate('This is $name.', mapping), 'This is Zope.')
self.assertEqual(
interpolate('This is ${name}.', mapping), 'This is Zope.')
# Test more than one interpolation variable
self.assertEqual(
interpolate('This is $name version $version.', mapping),
'This is Zope version 3x.')
self.assertEqual(
interpolate('This is ${name} version $version.', mapping),
'This is Zope version 3x.')
self.assertEqual(
interpolate('This is $name version ${version}.', mapping),
'This is Zope version 3x.')
self.assertEqual(
interpolate('This is ${name} version ${version}.', mapping),
'This is Zope version 3x.')
# Test escaping the $
self.assertEqual(
interpolate('This is $$name.', mapping), 'This is $$name.')
self.assertEqual(
interpolate('This is $${name}.', mapping), 'This is $${name}.')
# Test interpolation of non-string objects
self.assertEqual(interpolate('Number $number.', mapping), 'Number 3.')
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestInterpolation),
))
if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())
=== Added File Zope3/src/zope/i18n/tests/test_itranslationdomain.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 ITranslationDomain interface.
$Id: test_itranslationdomain.py,v 1.1 2004/03/08 23:36:00 srichter Exp $
"""
import unittest
from zope.interface.verify import verifyObject
from zope.interface import implements
from zope.component import getService
from zope.component.servicenames import Utilities
from zope.component.tests.placelesssetup import PlacelessSetup
from zope.i18n.negotiator import negotiator
from zope.i18n.interfaces import INegotiator, IUserPreferredLanguages
from zope.i18n.interfaces import ITranslationDomain
class Environment:
implements(IUserPreferredLanguages)
def __init__(self, langs=()):
self.langs = langs
def getPreferredLanguages(self):
return self.langs
class TestITranslationDomain(PlacelessSetup):
# This should be overwritten by every clas that inherits this test
def _getTranslationDomain(self):
pass
def setUp(self):
super(TestITranslationDomain, self).setUp()
self._domain = self._getTranslationDomain()
assert verifyObject(ITranslationDomain, self._domain)
# Setup the negotiator utility
utilities = getService(None, Utilities)
utilities.provideUtility(INegotiator, negotiator)
def testSimpleTranslate(self):
translate = self._domain.translate
eq = self.assertEqual
# Test that a given message id is properly translated in a supported
# language
eq(translate('short_greeting', target_language='de'), 'Hallo!')
# Same test, but use the context argument
context = Environment(('de', 'en'))
eq(translate('short_greeting', context=context), 'Hallo!')
def testDynamicTranslate(self):
translate = self._domain.translate
eq = self.assertEqual
# Testing both translation and interpolation
eq(translate('greeting', mapping={'name': 'Stephan'},
target_language='de'),
'Hallo Stephan, wie geht es Dir?')
def testNoTranslation(self):
translate = self._domain.translate
eq = self.assertEqual
# Test that an unknown message id returns None as a translation
eq(translate('glorp_smurf_hmpf', target_language='en'),
None)
def testNoTargetLanguage(self):
translate = self._domain.translate
eq = self.assertEqual
# Test that default is returned when no language can be negotiated
context = Environment(('xx', ))
eq(translate('short_greeting', context=context, default=42), 42)
# Test that default is returned when there's no destination language
eq(translate('short_greeting', default=42), 42)
def test_suite():
return unittest.TestSuite() # Deliberately empty
=== Added File Zope3/src/zope/i18n/tests/test_simpletranslationdomain.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 Domain.
$Id: test_simpletranslationdomain.py,v 1.1 2004/03/08 23:36:00 srichter Exp $
"""
import unittest
from zope.i18n.simpletranslationdomain import SimpleTranslationDomain
from zope.i18n.tests.test_itranslationdomain import TestITranslationDomain
data = {
('en', 'short_greeting'): 'Hello!',
('de', 'short_greeting'): 'Hallo!',
('en', 'greeting'): 'Hello $name, how are you?',
('de', 'greeting'): 'Hallo $name, wie geht es Dir?'}
class TestSimpleTranslationDomain(unittest.TestCase, TestITranslationDomain):
def setUp(self):
TestITranslationDomain.setUp(self)
def _getTranslationDomain(self):
domain = SimpleTranslationDomain('default', data)
return domain
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestSimpleTranslationDomain))
return suite
if __name__ == '__main__':
unittest.TextTestRunner().run(test_suite())
=== Added File Zope3/src/zope/i18n/tests/test_translationdomain.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 Domain.
$Id: test_translationdomain.py,v 1.1 2004/03/08 23:36:00 srichter Exp $
"""
import unittest, os
from zope.i18n.translationdomain import TranslationDomain
from zope.i18n.gettextmessagecatalog import GettextMessageCatalog
from zope.i18n.tests.test_itranslationdomain import \
TestITranslationDomain, Environment
from zope.i18n import MessageIDFactory
def testdir():
from zope.i18n import tests
return os.path.dirname(tests.__file__)
class TestGlobalTranslationDomain(unittest.TestCase, TestITranslationDomain):
def setUp(self):
TestITranslationDomain.setUp(self)
def _getTranslationDomain(self):
domain = TranslationDomain('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'))
domain.addCatalog(en_catalog)
domain.addCatalog(de_catalog)
return domain
def testNoTargetLanguage(self):
# Having a fallback would interfere with this test
self._domain.setLanguageFallbacks([])
TestITranslationDomain.testNoTargetLanguage(self)
def testSimpleNoTranslate(self):
translate = self._domain.translate
raises = self.assertRaises
eq = self.assertEqual
# Unset fallback translation languages
self._domain.setLanguageFallbacks([])
# Test that a translation in an unsupported language returns the
# default, if there is no fallback language
eq(translate('short_greeting', target_language='es'),
None)
eq(translate('short_greeting', target_language='es',
default='short_greeting'),
'short_greeting')
# Same test, but use the context argument instead of target_language
context = Environment()
eq(translate('short_greeting', context=context),
None)
eq(translate('short_greeting', context=context,
default='short_greeting'),
'short_greeting')
def testEmptyStringTranslate(self):
translate = self._domain.translate
self.assertEqual(translate(u'', target_language='en'), u'')
self.assertEqual(translate(u'', target_language='foo'), u'')
def testStringTranslate(self):
self.assertEqual(
self._domain.translate(u'short_greeting', 'default',
target_language='en'),
u'Hello!')
def testMessageIDTranslate(self):
self.assertEqual(
self._domain.translate(u'short_greeting', 'default',
target_language='en'),
u'Hello!')
def testSimpleFallbackTranslation(self):
translate = self._domain.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('short_greeting', target_language='es'),
u'Hello!')
# Same test, but use the context argument instead of target_language
context = Environment()
eq(translate('short_greeting', context=context),
u'Hello!')
def testInterpolationWithoutTranslation(self):
translate = self._domain.translate
self.assertEqual(
translate('42-not-there', target_language="en",
default="this ${that} the other",
mapping={"that": "THAT"}),
"this THAT the other")
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestGlobalTranslationDomain))
return suite
if __name__ == '__main__':
unittest.TextTestRunner().run(test_suite())
=== Zope3/src/zope/i18n/tests/test_imessagecatalog.py 1.2 => 1.3 ===
--- Zope3/src/zope/i18n/tests/test_imessagecatalog.py:1.2 Tue Mar 25 19:19:58 2003
+++ Zope3/src/zope/i18n/tests/test_imessagecatalog.py Mon Mar 8 18:36:00 2004
@@ -51,12 +51,12 @@
def testGetLanguage(self):
catalog = self._catalog
- self.assertEqual(catalog.getLanguage(), 'en')
+ self.assertEqual(catalog.language, 'en')
def testGetDomain(self):
catalog = self._catalog
- self.assertEqual(catalog.getDomain(), 'default')
+ self.assertEqual(catalog.domain, 'default')
def testGetIdentifier(self):
=== Zope3/src/zope/i18n/tests/test_messageid.py 1.5 => 1.6 ===
--- Zope3/src/zope/i18n/tests/test_messageid.py:1.5 Fri Feb 20 04:24:38 2004
+++ Zope3/src/zope/i18n/tests/test_messageid.py Mon Mar 8 18:36:00 2004
@@ -15,7 +15,6 @@
$Id$
"""
-
import unittest
from zope.testing.doctestunit import DocTestSuite
=== Removed File Zope3/src/zope/i18n/tests/test_globaltranslationservice.py ===
=== Removed File Zope3/src/zope/i18n/tests/test_itranslationservice.py ===
=== Removed File Zope3/src/zope/i18n/tests/test_simpletranslationservice.py ===
=== Removed File Zope3/src/zope/i18n/tests/test_translator.py ===
More information about the Zope3-Checkins
mailing list