[ZPT] CVS: Zope/lib/python/Products/PageTemplates/tests - __init__.py:1.3 testDTMLTests.py:1.8 testHTMLTests.py:1.15 testTALES.py:1.6

Florent Guillaume fg@nuxeo.com
Wed, 18 Sep 2002 11:13:18 -0400


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

Modified Files:
	__init__.py testDTMLTests.py testHTMLTests.py testTALES.py 
Log Message:
Merge of the Zope-2_6-i18n-branch into HEAD.

Impacted code:
- TAL: merge of the 2.7 i18n stuff, unicode fixes, tests.
- PageTemplates: addition of a global translation service and of its use
  by the TALES engine, unicode fixes, tests.
- StructuredText: unicode fixes, tests.


=== Zope/lib/python/Products/PageTemplates/tests/__init__.py 1.2 => 1.3 ===
--- Zope/lib/python/Products/PageTemplates/tests/__init__.py:1.2	Wed Aug 14 18:17:24 2002
+++ Zope/lib/python/Products/PageTemplates/tests/__init__.py	Wed Sep 18 11:12:46 2002
@@ -34,3 +34,4 @@
         assert aargs == args, "Harness method arguments"
         assert akwargs == kwargs, "Harness method keyword args"
         return result
+    


=== Zope/lib/python/Products/PageTemplates/tests/testDTMLTests.py 1.7 => 1.8 ===
--- Zope/lib/python/Products/PageTemplates/tests/testDTMLTests.py:1.7	Wed Aug 14 18:17:24 2002
+++ Zope/lib/python/Products/PageTemplates/tests/testDTMLTests.py	Wed Sep 18 11:12:46 2002
@@ -140,3 +140,4 @@
 
 if __name__=='__main__':
     main()
+


=== Zope/lib/python/Products/PageTemplates/tests/testHTMLTests.py 1.14 => 1.15 ===
--- Zope/lib/python/Products/PageTemplates/tests/testHTMLTests.py:1.14	Tue Sep  3 09:55:59 2002
+++ Zope/lib/python/Products/PageTemplates/tests/testHTMLTests.py	Wed Sep 18 11:12:46 2002
@@ -15,8 +15,9 @@
 
 from Products.PageTemplates.tests import util
 from Products.PageTemplates.PageTemplate import PageTemplate
-import ZODB
-from AccessControl import User, SecurityManager
+from Products.PageTemplates.GlobalTranslationService import \
+     setGlobalTranslationService
+from AccessControl import SecurityManager
 from AccessControl.SecurityManagement import noSecurityManager
 
 from Acquisition import Implicit
@@ -26,6 +27,10 @@
 class Folder(util.Base):
     pass
 
+class TestTranslationService:
+    def translate(self, domain, msgid, *args, **kw):
+        return "[%s](%s)" % (domain, msgid)
+
 
 class UnitTestSecurityPolicy:
     """
@@ -69,6 +74,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. '
@@ -126,8 +139,20 @@
     def checkBatchIteration(self):
         self.assert_expected(self.folder.t, 'CheckBatchIteration.html')
 
+    def checkUnicodeInserts(self):
+        self.assert_expected_unicode(self.folder.t, 'CheckUnicodeInserts.html')
+
+    def checkI18nTranslate(self):
+        self.assert_expected(self.folder.t, 'CheckI18nTranslate.html')
+
+    def checkI18nTranslateHooked(self):
+        old_ts = setGlobalTranslationService(TestTranslationService())
+        self.assert_expected(self.folder.t, 'CheckI18nTranslateHooked.html')
+        setGlobalTranslationService(old_ts)
+
 def test_suite():
     return unittest.makeSuite(HTMLTests, 'check')
 
 if __name__=='__main__':
-    unittest.main(defaultTest='test_suite')
+   main()
+


=== Zope/lib/python/Products/PageTemplates/tests/testTALES.py 1.5 => 1.6 ===
--- Zope/lib/python/Products/PageTemplates/tests/testTALES.py:1.5	Thu Aug 29 10:00:08 2002
+++ Zope/lib/python/Products/PageTemplates/tests/testTALES.py	Wed Sep 18 11:12: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):
@@ -85,6 +96,11 @@
         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'''
         ctxt = self.getContext()
@@ -114,4 +130,4 @@
     return unittest.makeSuite(TALESTests)
 
 if __name__=='__main__':
-    unittest.main(defaultTest='test_suite')
+    main()