[Zope3-checkins] CVS: Zope3/src/zope/i18n/tests - test_globaltranslationservice.py:1.10 test_itranslationservice.py:1.5
Barry Warsaw
barry@zope.com
Thu, 17 Apr 2003 16:05:44 -0400
Update of /cvs-repository/Zope3/src/zope/i18n/tests
In directory cvs.zope.org:/tmp/cvs-serv14704/src/zope/i18n/tests
Modified Files:
test_globaltranslationservice.py test_itranslationservice.py
Log Message:
Make the various i18n interfaces more consistent in their argument
order. Some required domain before msgid, others had those two
reversed. We standardize on msgid before domain because msgid can be
a MessageID instance which carries its domain around with it. So in
that case we don't need to specify domain and can make it an argument
with a default value of None.
Update all found call sites of the old order, fixed interfaces and
tests. Ran the tests and z3.py with Python 2.2.2 -- I hope I got them
all!
=== Zope3/src/zope/i18n/tests/test_globaltranslationservice.py 1.9 => 1.10 ===
--- Zope3/src/zope/i18n/tests/test_globaltranslationservice.py:1.9 Fri Apr 11 09:20:13 2003
+++ Zope3/src/zope/i18n/tests/test_globaltranslationservice.py Thu Apr 17 16:05:13 2003
@@ -57,31 +57,27 @@
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
# default, if there is no fallback language
- eq(translate('default', 'short_greeting', target_language='es'),
+ eq(translate('short_greeting', 'default', target_language='es'),
None)
- eq(translate('default', 'short_greeting',
+ eq(translate('short_greeting', 'default',
target_language='es', default='short_greeting'),
'short_greeting')
# Same test, but use the context argument instead of target_language
context = Environment()
- eq(translate('default', 'short_greeting', context=context),
+ eq(translate('short_greeting', 'default', context=context),
None)
- eq(translate('default', 'short_greeting', context=context,
+ eq(translate('short_greeting', 'default', context=context,
default='short_greeting'),
'short_greeting')
- # Test that at least one of context or target_language is given
- raises(TypeError, translate, 'short_greeting', context=None)
def testStringTranslate(self):
translate = self._service.translate
- self.assertEqual(translate('default', u'short_greeting',
+ self.assertEqual(translate(u'short_greeting', 'default',
target_language='en'),
u'Hello!')
@@ -91,18 +87,17 @@
GettextMessageCatalog('en', 'alt',
os.path.join(path, 'en-default.mo')))
translate = self._service.translate
- self.assertEqual(translate('alt', u'special',
+ self.assertEqual(translate(u'special', 'alt',
target_language='en'),
u'Wow')
def testMessageIDTranslate(self):
translate = self._service.translate
- self.assertEqual(translate('default', u'short_greeting',
+ self.assertEqual(translate(u'short_greeting', 'default',
target_language='en'),
u'Hello!')
msgid = MessageIDFactory('alt')('short_greeting')
- self.assertEqual(translate('default', msgid,
- target_language='en'),
+ self.assertEqual(translate(msgid, 'default', target_language='en'),
u'Hey!')
@@ -112,26 +107,26 @@
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'),
+ eq(translate('short_greeting', 'default', 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),
+ eq(translate('short_greeting', 'default', context=context),
u'Hello!')
def testInterpolationWithoutTranslation(self):
translate = self._service.translate
- self.assertEqual(translate("default", "42-not-there",
+ self.assertEqual(translate('42-not-there', 'default',
target_language="en",
default="this ${that} the other",
mapping={"that": "THAT"}),
"this THAT the other")
- self.assertEqual(translate("no-such-domain", "42-not-there",
+ self.assertEqual(translate("42-not-there", "no-such-domain",
target_language="en",
default="this ${that} the other",
mapping={"that": "THAT"}),
"this THAT the other")
- self.assertEqual(translate("no-such-domain", "42-not-there",
+ self.assertEqual(translate("42-not-there", "no-such-domain",
target_language="en",
mapping={"that": "THAT"}),
None)
=== Zope3/src/zope/i18n/tests/test_itranslationservice.py 1.4 => 1.5 ===
--- Zope3/src/zope/i18n/tests/test_itranslationservice.py:1.4 Fri Apr 11 09:20:13 2003
+++ Zope3/src/zope/i18n/tests/test_itranslationservice.py Thu Apr 17 16:05:13 2003
@@ -82,19 +82,19 @@
eq = self.assertEqual
# Test that a given message id is properly translated in a supported
# language
- eq(translate('default', 'short_greeting', target_language='de'),
+ eq(translate('short_greeting', 'default', target_language='de'),
'Hallo!')
# Same test, but use the context argument
context = Environment(('de', 'en'))
- eq(translate('default', 'short_greeting', context=context),
+ eq(translate('short_greeting', 'default', context=context),
'Hallo!')
def testSimpleTranslate_bad_domain(self):
translate = self._service.translate
eq = self.assertEqual
- eq(translate('defaultnot', 'short_greeting', target_language='de'),
+ eq(translate('short_greeting', 'defaultnot', target_language='de'),
None)
- eq(translate('defaultnot', 'short_greeting', target_language='de',
+ eq(translate('short_greeting', 'defaultnot', target_language='de',
default=42),
42)
@@ -102,7 +102,7 @@
translate = self._service.translate
eq = self.assertEqual
# Testing both translation and interpolation
- eq(translate('default', 'greeting', mapping={'name': 'Stephan'},
+ eq(translate('greeting', 'default', mapping={'name': 'Stephan'},
target_language='de'),
'Hallo Stephan, wie geht es Dir?')
@@ -110,7 +110,7 @@
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'),
+ eq(translate('glorp_smurf_hmpf', 'default', target_language='en'),
None)
def testNoTargetLanguage(self):
@@ -118,12 +118,12 @@
eq = self.assertEqual
# Test that default is returned when no language can be negotiated
context = Environment(('xx', ))
- eq(translate('default', 'short_greeting', context=context,
+ eq(translate('short_greeting', 'default', context=context,
default=42),
42)
# Test that default is returned when there's no destination language
- eq(translate('default', 'short_greeting', default=42),
+ eq(translate('short_greeting', 'default', default=42),
42)