[Zope3-checkins] CVS: Zope3/src/zope/pagetemplate/tests - test_tales.py:1.1.2.2

Fred L. Drake, Jr. fred@zope.com
Mon, 23 Dec 2002 16:41:57 -0500


Update of /cvs-repository/Zope3/src/zope/pagetemplate/tests
In directory cvs.zope.org:/tmp/cvs-serv12720

Modified Files:
      Tag: NameGeddon-branch
	test_tales.py 
Log Message:
Update to reflect the new world order of naming.  Add harness1 to this
module as Harness, since the original was lost and harness2 wasn't
used.


=== Zope3/src/zope/pagetemplate/tests/test_tales.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/pagetemplate/tests/test_tales.py:1.1.2.1	Mon Dec 23 14:32:59 2002
+++ Zope3/src/zope/pagetemplate/tests/test_tales.py	Mon Dec 23 16:41:56 2002
@@ -11,33 +11,34 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-import os, sys, unittest
+import os
+import sys
+import unittest
 
-from Zope.PageTemplate import TALES
-from Zope.PageTemplate.tests import harness1
+from zope.pagetemplate import tales
 
 
 class TALESTests(unittest.TestCase):
 
     def testIterator0(self):
         # Test sample Iterator class
-        context = harness1()
-        it = TALES.Iterator('name', (), context)
+        context = Harness()
+        it = tales.Iterator('name', (), context)
         assert not it.next(), "Empty iterator"
         context._complete_()
 
     def testIterator1(self):
         # Test sample Iterator class
-        context = harness1()
-        it = TALES.Iterator('name', (1,), context)
+        context = Harness()
+        it = tales.Iterator('name', (1,), context)
         context._assert_('setLocal', 'name', 1)
         assert it.next() and not it.next(), "Single-element iterator"
         context._complete_()
 
     def testIterator2(self):
         # Test sample Iterator class
-        context = harness1()
-        it = TALES.Iterator('text', 'text', context)
+        context = Harness()
+        it = tales.Iterator('text', 'text', context)
         for c in 'text':
             context._assert_('setLocal', 'text', c)
         for c in 'text':
@@ -47,49 +48,49 @@
 
     def testRegisterType(self):
         # Test expression type registration
-        e = TALES.ExpressionEngine()
-        e.registerType('simple', TALES.SimpleExpr)
-        assert e.getTypes()['simple'] == TALES.SimpleExpr
+        e = tales.ExpressionEngine()
+        e.registerType('simple', tales.SimpleExpr)
+        assert e.getTypes()['simple'] == tales.SimpleExpr
 
     def testRegisterTypeUnique(self):
         # Test expression type registration uniqueness
-        e = TALES.ExpressionEngine()
-        e.registerType('simple', TALES.SimpleExpr)
+        e = tales.ExpressionEngine()
+        e.registerType('simple', tales.SimpleExpr)
         try:
-            e.registerType('simple', TALES.SimpleExpr)
-        except TALES.RegistrationError:
+            e.registerType('simple', tales.SimpleExpr)
+        except tales.RegistrationError:
             pass
         else:
             assert 0, "Duplicate registration accepted."
 
     def testRegisterTypeNameConstraints(self):
         # Test constraints on expression type names
-        e = TALES.ExpressionEngine()
+        e = tales.ExpressionEngine()
         for name in '1A', 'A!', 'AB ':
             try:
-                e.registerType(name, TALES.SimpleExpr)
-            except TALES.RegistrationError:
+                e.registerType(name, tales.SimpleExpr)
+            except tales.RegistrationError:
                 pass
             else:
                 assert 0, 'Invalid type name "%s" accepted.' % name
 
     def testCompile(self):
         # Test expression compilation
-        e = TALES.ExpressionEngine()
-        e.registerType('simple', TALES.SimpleExpr)
+        e = tales.ExpressionEngine()
+        e.registerType('simple', tales.SimpleExpr)
         ce = e.compile('simple:x')
         assert ce(None) == ('simple', 'x'), (
             'Improperly compiled expression %s.' % `ce`)
 
     def testGetContext(self):
         # Test Context creation
-        TALES.ExpressionEngine().getContext()
-        TALES.ExpressionEngine().getContext(v=1)
-        TALES.ExpressionEngine().getContext(x=1, y=2)
+        tales.ExpressionEngine().getContext()
+        tales.ExpressionEngine().getContext(v=1)
+        tales.ExpressionEngine().getContext(x=1, y=2)
 
     def getContext(self, **kws):
-        e = TALES.ExpressionEngine()
-        e.registerType('simple', TALES.SimpleExpr)
+        e = tales.ExpressionEngine()
+        e.registerType('simple', tales.SimpleExpr)
         return apply(e.getContext, (), kws)
 
     def testContext0(self):
@@ -122,6 +123,30 @@
         assert c['g'] == 1, "Global from inner scope"
 
         ctxt.endScope()
+
+
+class Harness:
+    def __init__(self):
+        self.__callstack = []
+
+    def _assert_(self, name, *args, **kwargs):
+        self.__callstack.append((name, args, kwargs))
+
+    def _complete_(self):
+        assert len(self.__callstack) == 0, "Harness methods called"
+
+    def __getattr__(self, name):
+        cs = self.__callstack
+        assert len(cs), 'Unexpected harness method call "%s".' % name
+        assert cs[0][0] == name, (
+            'Harness method name "%s" called, "%s" expected.' %
+            (name, cs[0][0]) )
+        return self._method_
+
+    def _method_(self, *args, **kwargs):
+        name, aargs, akwargs = self.__callstack.pop(0)
+        assert aargs == args, "Harness method arguments"
+        assert akwargs == kwargs, "Harness method keyword args"
 
 
 def test_suite():