[ZPT] CVS: Packages/TAL - test_htmlparser.py:1.3
guido@digicool.com
guido@digicool.com
Wed, 21 Mar 2001 17:41:03 -0500 (EST)
Update of /cvs-repository/Packages/TAL/test
In directory korak:/tmp/cvs-serv17590
Modified Files:
test_htmlparser.py
Log Message:
Fix module docstring.
Add test for finish_startendtag().
Style nits:
Add blank lines between class header and first method definition.
Move _parse_error() to earlier in the class.
--- Updated File test_htmlparser.py in package Packages/TAL --
--- test_htmlparser.py 2001/03/20 03:25:26 1.2
+++ test_htmlparser.py 2001/03/21 22:41:03 1.3
@@ -1,5 +1,5 @@
#! /usr/bin/env python1.5
-"""Test suite for nsgmllib.py."""
+"""Tests for HTMLParser.py."""
import sys
@@ -10,6 +10,7 @@
class EventCollector(HTMLParser.HTMLParser):
+
def __init__(self):
self.events = []
self.append = self.events.append
@@ -35,6 +36,9 @@
def finish_starttag(self, tag, attrs):
self.append(("starttag", tag, attrs))
+ def finish_startendtag(self, tag, attrs):
+ self.append(("startendtag", tag, attrs))
+
def finish_endtag(self, tag):
self.append(("endtag", tag))
@@ -57,6 +61,7 @@
class HTMLParserTestCase(unittest.TestCase):
+
def _run_check(self, source, events):
parser = EventCollector()
if isinstance(source, type([])):
@@ -67,6 +72,13 @@
parser.close()
assert parser.get_events() == events, parser.get_events()
+ def _parse_error(self, source):
+ def parse(source=source):
+ parser = HTMLParser.HTMLParser()
+ parser.feed(source)
+ parser.close()
+ self.assertRaises(HTMLParser.HTMLParseError, parse)
+
def check_processing_instruction_only(self):
self._run_check("<?processing instruction>", [
("pi", "processing instruction"),
@@ -155,12 +167,19 @@
def check_starttag_junk_chars(self):
self._parse_error("<a $>")
- def _parse_error(self, source):
- def parse(source=source):
- parser = HTMLParser.HTMLParser()
- parser.feed(source)
- parser.close()
- self.assertRaises(HTMLParser.HTMLParseError, parse)
+ def check_startendtag(self):
+ self._run_check("<p/>", [
+ ("startendtag", "p", []),
+ ])
+ self._run_check("<p></p>", [
+ ("starttag", "p", []),
+ ("endtag", "p"),
+ ])
+ self._run_check("<p><img src='foo' /></p>", [
+ ("starttag", "p", []),
+ ("startendtag", "img", [("src", "foo")]),
+ ("endtag", "p"),
+ ])
# Support for the Zope regression test framework: