[Zope-Checkins] CVS: Zope/lib/python/Products/PageTemplates/tests - testHTMLTests.py:1.14.4.2 testTALES.py:1.5.4.2

Florent Guillaume fg@nuxeo.com
Sun, 15 Sep 2002 20:01:16 -0400


Update of /cvs-repository/Zope/lib/python/Products/PageTemplates/tests
In directory cvs.zope.org:/tmp/cvs-serv1822/Products/PageTemplates/tests

Modified Files:
      Tag: Zope-2_6-i18n-branch
	testHTMLTests.py testTALES.py 
Log Message:
Improved support for Unicode in TAL and ZPT.
Added tests that exercise that.


=== Zope/lib/python/Products/PageTemplates/tests/testHTMLTests.py 1.14.4.1 => 1.14.4.2 ===
--- Zope/lib/python/Products/PageTemplates/tests/testHTMLTests.py:1.14.4.1	Sun Sep 15 18:43:34 2002
+++ Zope/lib/python/Products/PageTemplates/tests/testHTMLTests.py	Sun Sep 15 20:00:46 2002
@@ -68,6 +68,14 @@
         out = apply(t, args, kwargs)
         util.check_html(expect, out)
 
+    def assert_expected_unicode(self, t, fname, *args, **kwargs):
+        t.write(util.read_input(fname))
+        assert not t._v_errors, 'Template errors: %s' % t._v_errors
+        expect = util.read_output(fname)
+        expect = unicode(expect, 'utf8')
+        out = apply(t, args, kwargs)
+        util.check_html(expect, out)
+
     def getProducts(self):
         return [
            {'description': 'This is the tee for those who LOVE Zope. '
@@ -124,6 +132,9 @@
 
     def checkBatchIteration(self):
         self.assert_expected(self.folder.t, 'CheckBatchIteration.html')
+
+    def checkUnicodeInserts(self):
+        self.assert_expected_unicode(self.folder.t, 'CheckUnicodeInserts.html')
 
 def test_suite():
     return unittest.makeSuite(HTMLTests, 'check')


=== Zope/lib/python/Products/PageTemplates/tests/testTALES.py 1.5.4.1 => 1.5.4.2 ===
--- Zope/lib/python/Products/PageTemplates/tests/testTALES.py:1.5.4.1	Sun Sep 15 18:43:34 2002
+++ Zope/lib/python/Products/PageTemplates/tests/testTALES.py	Sun Sep 15 20:00:46 2002
@@ -4,6 +4,16 @@
 from Products.PageTemplates.tests import harness1
 import string
 
+class DummyUnicodeExpr:
+    '''Dummy expression type handler returning unicode'''
+    def __init__(self, name, expr, engine):
+        self._name = name
+        self._expr = expr
+    def __call__(self, econtext):
+        return unicode(self._expr, 'latin1')
+    def __repr__(self):
+        return '<SimpleExpr %s %s>' % (self._name, `self._expr`)
+
 class TALESTests(unittest.TestCase):
 
     def testIterator0(self):
@@ -77,6 +87,7 @@
     def getContext(self, **kws):
         e = TALES.Engine()
         e.registerType('simple', TALES.SimpleExpr)
+        e.registerType('unicode', DummyUnicodeExpr)
         return apply(e.getContext, (), kws)
 
     def testContext0(self):
@@ -84,6 +95,11 @@
         se = self.getContext().evaluate('simple:x')
         assert se == ('simple', 'x'), (
             'Improperly evaluated expression %s.' % `se`)
+
+    def testContextUnicode(self):
+        '''Test evaluateText on unicode-returning expressions'''
+        se = self.getContext().evaluateText('unicode:\xe9')
+        self.assertEqual(se, u'\xe9')
 
     def testVariables(self):
         '''Test variables'''