[Zope3-checkins] CVS: Zope3/src/zope/tal/tests -
test_htmltalparser.py:1.6 test_talinterpreter.py:1.4
Stephan Richter
srichter at cosmos.phy.tufts.edu
Fri Aug 8 20:05:35 EDT 2003
Update of /cvs-repository/Zope3/src/zope/tal/tests
In directory cvs.zope.org:/tmp/cvs-serv27987/tests
Modified Files:
test_htmltalparser.py test_talinterpreter.py
Log Message:
Fixed a couple of bugs in TAL. There are two more tests in the branch that
are failing, but they uncover a deep, deep issue, so that we all (Barry,
Fred and I) will try on Monday again.
=== Zope3/src/zope/tal/tests/test_htmltalparser.py 1.5 => 1.6 ===
--- Zope3/src/zope/tal/tests/test_htmltalparser.py:1.5 Fri Apr 25 14:07:22 2003
+++ Zope3/src/zope/tal/tests/test_htmltalparser.py Fri Aug 8 19:04:59 2003
@@ -713,32 +713,40 @@
def test_i18n_data_with_name(self):
# input/test29.html
self._run_check('''\
-At the tone the time will be
+<div i18n:translate="">At the tone the time will be
<span i18n:data="here/currentTime"
i18n:translate="timefmt"
- i18n:name="time">2:32 pm</span>... beep!
-''', [
- ('rawtextBeginScope',
- ('At the tone the time will be\n',
- 0,
- (2, 0),
- 0,
- {'i18n:data': 'here/currentTime',
- 'i18n:name': 'time',
- 'i18n:translate': 'timefmt'})),
- ('insertTranslation',
- ('timefmt',
- [('startTag',
- ('span',
- [('i18n:data', 'here/currentTime', 'i18n'),
- ('i18n:translate', 'timefmt', 'i18n'),
- ('i18n:name', 'time', 'i18n')])),
- ('i18nVariable', ('time', [], None))],
- '$here/currentTime$')),
- ('endScope', ()),
- ('rawtextColumn', ('... beep!\n', 0))
- ])
+ i18n:name="time">2:32 pm</span>... beep!</div>
+''',
+[('setPosition', (1, 0)),
+ ('beginScope', {'i18n:translate': ''}),
+ ('startTag', ('div', [('i18n:translate', '', 'i18n')])),
+ ('insertTranslation',
+ ('',
+ [('rawtextBeginScope',
+ ('At the tone the time will be\n',
+ 0,
+ (2, 0),
+ 0,
+ {'i18n:data': 'here/currentTime',
+ 'i18n:name': 'time',
+ 'i18n:translate': 'timefmt'})),
+ ('insertTranslation',
+ ('timefmt',
+ [('startTag',
+ ('span',
+ [('i18n:data', 'here/currentTime', 'i18n'),
+ ('i18n:translate', 'timefmt', 'i18n'),
+ ('i18n:name', 'time', 'i18n')])),
+ ('i18nVariable', ('time', [], None))],
+ '$here/currentTime$')),
+ ('endScope', ()),
+ ('rawtextOffset', ('... beep!', 9))])),
+ ('endScope', ()),
+ ('rawtextColumn', ('</div>\n', 0))]
+)
+
def test_i18n_explicit_msgid_with_name(self):
# input/test26.html
self._run_check('''\
=== Zope3/src/zope/tal/tests/test_talinterpreter.py 1.3 => 1.4 ===
--- Zope3/src/zope/tal/tests/test_talinterpreter.py:1.3 Tue Jul 22 08:37:31 2003
+++ Zope3/src/zope/tal/tests/test_talinterpreter.py Fri Aug 8 19:04:59 2003
@@ -22,9 +22,9 @@
from zope.tal.taldefs import METALError, I18NError
from zope.tal.htmltalparser import HTMLTALParser
from zope.tal.talinterpreter import TALInterpreter
-from zope.tal.dummyengine import DummyEngine
+from zope.tal.dummyengine import DummyEngine, DummyTranslationService
from zope.tal.tests import utils
-
+from zope.i18n.messageid import MessageID
class TestCaseBase(unittest.TestCase):
@@ -59,6 +59,79 @@
self.macro[0] = ("version", "duh")
+class I18NCornerTestCase(TestCaseBase):
+
+ def setUp(self):
+ self.engine = DummyEngine()
+ self.engine.setLocal('foo', MessageID('FoOvAlUe', 'default'))
+ self.engine.setLocal('bar', 'BaRvAlUe')
+
+ def _check(self, program, expected):
+ result = StringIO()
+ self.interpreter = TALInterpreter(program, {}, self.engine,
+ stream=result)
+ self.interpreter()
+ self.assertEqual(expected, result.getvalue())
+
+ def test_simple_messageid_translate(self):
+ # This test is mainly here to make sure our DummyEngine works
+ # correctly.
+ program, macros = self._compile('<span tal:content="foo"/>')
+ self._check(program, '<span>FOOVALUE</span>\n')
+
+ program, macros = self._compile('<span tal:replace="foo"/>')
+ self._check(program, 'FOOVALUE\n')
+
+ def test_replace_with_messageid_and_i18nname(self):
+ program, macros = self._compile(
+ '<div i18n:translate="" >'
+ '<span tal:replace="foo" i18n:name="foo_name"/>'
+ '</div>')
+ self._check(program, '<div>FOOVALUE</div>\n')
+
+ def test_pythonexpr_replace_with_messageid_and_i18nname(self):
+ program, macros = self._compile(
+ '<div i18n:translate="" >'
+ '<span tal:replace="python: foo" i18n:name="foo_name"/>'
+ '</div>')
+ self._check(program, '<div>FOOVALUE</div>\n')
+
+ def test_structure_replace_with_messageid_and_i18nname(self):
+ program, macros = self._compile(
+ '<div i18n:translate="" >'
+ '<span tal:replace="structure foo" i18n:name="foo_name"/>'
+ '</div>')
+ self._check(program, '<div>FOOVALUE</div>\n')
+
+ def test_complex_replace_with_messageid_and_i18nname(self):
+ program, macros = self._compile(
+ '<div i18n:translate="" >'
+ '<em i18n:name="foo_name">'
+ '<span tal:replace="foo"/>'
+ '</em>'
+ '</div>')
+ self._check(program, '<div>FOOVALUE</div>\n')
+
+ def test_content_with_messageid_and_i18nname(self):
+ program, macros = self._compile(
+ '<div i18n:translate="" >'
+ '<span tal:content="foo" i18n:name="foo_name"/>'
+ '</div>')
+ self._check(program, '<div><span>FOOVALUE</span></div>\n')
+
+ def test_content_with_messageid_and_i18nname_and_i18ntranslate(self):
+ # Let's tell the user this is incredibly silly!
+ self.assertRaises(
+ I18NError, self._compile,
+ '<span i18n:translate="" tal:content="foo" i18n:name="foo_name"/>')
+
+ def test_content_with_plaintext_and_i18nname_and_i18ntranslate(self):
+ # Let's tell the user this is incredibly silly!
+ self.assertRaises(
+ I18NError, self._compile,
+ '<span i18n:translate="" i18n:name="color_name">green</span>')
+
+
class I18NErrorsTestCase(TestCaseBase):
def _check(self, src, msg):
@@ -124,6 +197,7 @@
suite = unittest.makeSuite(I18NErrorsTestCase)
suite.addTest(unittest.makeSuite(MacroErrorsTestCase))
suite.addTest(unittest.makeSuite(OutputPresentationTestCase))
+ suite.addTest(unittest.makeSuite(I18NCornerTestCase))
return suite
if __name__ == "__main__":
More information about the Zope3-Checkins
mailing list