[ZPT] CVS: Packages/TAL - test_htmlparser.py:1.10

guido@digicool.com guido@digicool.com
Wed, 28 Mar 2001 19:02:22 -0500 (EST)


Update of /cvs-repository/Packages/TAL/test
In directory korak:/tmp/cvs-serv15213

Modified Files:
	test_htmlparser.py 
Log Message:
Refactor the testcase class a bit along to allow for prologue and
epilogue and initial and final events.  (This is not used anywhere but
I thought it was neat, and it matches what I did in
test_htmltalparser.py.)



--- Updated File test_htmlparser.py in package Packages/TAL --
--- test_htmlparser.py	2001/03/26 16:48:33	1.9
+++ test_htmlparser.py	2001/03/29 00:02:21	1.10
@@ -69,17 +69,28 @@
         EventCollector.handle_starttag(self, tag, attrs)
         self.append(("starttag_text", self.get_starttag_text()))
 
-class HTMLParserTestCase(unittest.TestCase):
 
+class TestCaseBase(unittest.TestCase):
+
+    # Constant pieces of source and events
+    prologue = ""
+    epilogue = ""
+    initial_events = []
+    final_events = []
+
     def _run_check(self, source, events, collector=EventCollector):
         parser = collector()
+        parser.feed(self.prologue)
         if isinstance(source, type([])):
             for s in source:
                 parser.feed(s)
         else:
             parser.feed(source)
+        parser.feed(self.epilogue)
         parser.close()
-        self.assert_(parser.get_events() == events, parser.get_events())
+        self.assert_(parser.get_events() ==
+                     self.initial_events + events + self.final_events,
+                     parser.get_events())
 
     def _run_check_extra(self, source, events):
         self._run_check(source, events, EventCollectorExtra)
@@ -90,6 +101,9 @@
             parser.feed(source)
             parser.close()
         self.assertRaises(HTMLParser.HTMLParseError, parse)
+
+
+class HTMLParserTestCase(TestCaseBase):
 
     def check_processing_instruction_only(self):
         self._run_check("<?processing instruction>", [