Commit ce3191fa authored by Fred Drake's avatar Fred Drake

Refactor _compile() into a base class, and add a new test that checks
the line-wrapping of attributes by TALInterpreter.do_startTag().
parent 6ae5b596
...@@ -6,13 +6,15 @@ import sys ...@@ -6,13 +6,15 @@ import sys
import utils import utils
import unittest import unittest
from StringIO import StringIO
from TAL.TALDefs import METALError from TAL.TALDefs import METALError
from TAL.HTMLTALParser import HTMLTALParser from TAL.HTMLTALParser import HTMLTALParser
from TAL.TALInterpreter import TALInterpreter from TAL.TALInterpreter import TALInterpreter
from TAL.DummyEngine import DummyEngine from TAL.DummyEngine import DummyEngine
class MacroErrorsTestCase(unittest.TestCase): class TestCaseBase(unittest.TestCase):
def _compile(self, source): def _compile(self, source):
parser = HTMLTALParser() parser = HTMLTALParser()
...@@ -20,6 +22,9 @@ class MacroErrorsTestCase(unittest.TestCase): ...@@ -20,6 +22,9 @@ class MacroErrorsTestCase(unittest.TestCase):
program, macros = parser.getCode() program, macros = parser.getCode()
return program, macros return program, macros
class MacroErrorsTestCase(TestCaseBase):
def setUp(self): def setUp(self):
dummy, macros = self._compile('<p metal:define-macro="M">Booh</p>') dummy, macros = self._compile('<p metal:define-macro="M">Booh</p>')
self.macro = macros['M'] self.macro = macros['M']
...@@ -42,9 +47,32 @@ class MacroErrorsTestCase(unittest.TestCase): ...@@ -42,9 +47,32 @@ class MacroErrorsTestCase(unittest.TestCase):
self.macro[0] = ("version", "duh") 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(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(MacroErrorsTestCase, "check_")) suite.addTest(unittest.makeSuite(MacroErrorsTestCase, "check_"))
suite.addTest(unittest.makeSuite(OutputPresentationTestCase, "check_"))
return suite return suite
......
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