[ZPT] CVS: Packages/TAL - test_talinterpreter.py:1.2

fred@digicool.com fred@digicool.com
Tue, 26 Jun 2001 10:33:23 -0400 (EDT)


Update of /cvs-repository/Packages/TAL/tests
In directory korak.digicool.com:/tmp/cvs-serv9073

Modified Files:
	test_talinterpreter.py 
Log Message:

Refactor _compile() into a base class, and add a new test that checks
the line-wrapping of attributes by TALInterpreter.do_startTag().



--- Updated File test_talinterpreter.py in package Packages/TAL --
--- test_talinterpreter.py	2001/04/10 02:48:49	1.1
+++ test_talinterpreter.py	2001/06/26 14:33:23	1.2
@@ -6,13 +6,15 @@
 import utils
 import unittest
 
+from StringIO import StringIO
+
 from TAL.TALDefs import METALError
 from TAL.HTMLTALParser import HTMLTALParser
 from TAL.TALInterpreter import TALInterpreter
 from TAL.DummyEngine import DummyEngine
 
 
-class MacroErrorsTestCase(unittest.TestCase):
+class TestCaseBase(unittest.TestCase):
 
     def _compile(self, source):
         parser = HTMLTALParser()
@@ -20,6 +22,9 @@
         program, macros = parser.getCode()
         return program, macros
 
+
+class MacroErrorsTestCase(TestCaseBase):
+
     def setUp(self):
         dummy, macros = self._compile('<p metal:define-macro="M">Booh</p>')
         self.macro = macros['M']
@@ -42,9 +47,32 @@
         self.macro[0] = ("version", "duh")
 
 
+class OutputPresentationTestCase(TestCaseBase):
+
+    def check_attribute_wrapping(self):
+        # To make sure the attribute-wrapping code is invoked, we have to
+        # include at least one TAL/METAL attribute to avoid having the start
+        # tag optimized into a rawtext instruction.
+        INPUT = r"""
+        <html this='element' has='a' lot='of' attributes=', so' the='output'
+              needs='to' be='line' wrapped='.' tal:define='foo nothing'>
+        </html>"""
+        EXPECTED = r'''
+        <html this="element" has="a" lot="of"
+              attributes=", so" the="output" needs="to"
+              be="line" wrapped=".">
+        </html>''' "\n"
+        program, macros = self._compile(INPUT)
+        sio = StringIO()
+        interp = TALInterpreter(program, {}, DummyEngine(), sio, wrap=60)
+        interp()
+        self.assertEqual(sio.getvalue(), EXPECTED)
+
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(MacroErrorsTestCase, "check_"))
+    suite.addTest(unittest.makeSuite(OutputPresentationTestCase, "check_"))
     return suite