Use saner test fixtures from Zope 3 tests (which are undoubtedly

the offspring of these insane Zope 2 test fixtures).
parent a44644aa
def all():
import testTALES
return testTALES.test_suite()
class harness1:
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"
class harness2(harness1):
def _assert_(self, name, result, *args, **kwargs):
self.__callstack.append((name, result, args, kwargs))
def _method_(self, *args, **kwargs):
name, result, aargs, akwargs = self.__callstack.pop(0)
assert aargs == args, "Harness method arguments"
assert akwargs == kwargs, "Harness method keyword args"
return result
# make this directory a package
import os, sys, unittest
from Products.PageTemplates import TALES
from Products.PageTemplates.tests import harness1
from zope.tales.tests.test_tales import Harness
import string
class DummyUnicodeExpr:
......@@ -18,14 +18,14 @@ class TALESTests(unittest.TestCase):
def testIterator0(self):
'''Test sample Iterator class'''
context = harness1()
context = Harness(self)
it = TALES.Iterator('name', (), context)
assert not it.next(), "Empty iterator"
context._complete_()
def testIterator1(self):
'''Test sample Iterator class'''
context = harness1()
context = Harness(self)
it = TALES.Iterator('name', (1,), context)
context._assert_('setLocal', 'name', 1)
assert it.next() and not it.next(), "Single-element iterator"
......@@ -33,7 +33,7 @@ class TALESTests(unittest.TestCase):
def testIterator2(self):
'''Test sample Iterator class'''
context = harness1()
context = Harness(self)
it = TALES.Iterator('text', 'text', context)
for c in 'text':
context._assert_('setLocal', 'text', c)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment