[Python-checkins] CVS: python/dist/src/Lib/test test_sgmllib.py,1.1,1.2
Fred L. Drake
fdrake@users.sourceforge.net
Mon, 24 Sep 2001 13:22:11 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv15870/test
Modified Files:
test_sgmllib.py
Log Message:
Added several new tests to check the behavior with respect to doctype
declarations and weird markup that we used to accept & ignore that recent
versions raised an exception for; the original behavior has been restored
and augmented (the user can decide what to do if they care; the default is
to ignore it as done in early versions).
Index: test_sgmllib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_sgmllib.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** test_sgmllib.py 2001/07/16 18:52:40 1.1
--- test_sgmllib.py 2001/09/24 20:22:09 1.2
***************
*** 55,58 ****
--- 55,61 ----
self.append(("pi", data))
+ def unknown_decl(self, decl):
+ self.append(("unknown decl", decl))
+
class CDATAEventCollector(EventCollector):
***************
*** 66,75 ****
collector = EventCollector
! def check_events(self, source, expected_events):
parser = self.collector()
! for s in source:
! parser.feed(s)
! parser.close()
! events = parser.get_events()
if events != expected_events:
self.fail("received events did not match expected events\n"
--- 69,90 ----
collector = EventCollector
! def get_events(self, source):
parser = self.collector()
! try:
! for s in source:
! parser.feed(s)
! parser.close()
! except:
! #self.events = parser.events
! raise
! return parser.get_events()
!
! def check_events(self, source, expected_events):
! try:
! events = self.get_events(source)
! except:
! import sys
! #print >>sys.stderr, pprint.pformat(self.events)
! raise
if events != expected_events:
self.fail("received events did not match expected events\n"
***************
*** 88,91 ****
--- 103,131 ----
% (source, pprint.pformat(parser.get_events())))
+ def test_doctype_decl_internal(self):
+ inside = """\
+ DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01//EN'
+ SYSTEM 'http://www.w3.org/TR/html401/strict.dtd' [
+ <!ELEMENT html - O EMPTY>
+ <!ATTLIST html
+ version CDATA #IMPLIED
+ profile CDATA 'DublinCore'>
+ <!NOTATION datatype SYSTEM 'http://xml.python.org/notations/python-module'>
+ <!ENTITY myEntity 'internal parsed entity'>
+ <!ENTITY anEntity SYSTEM 'http://xml.python.org/entities/something.xml'>
+ <!ENTITY % paramEntity 'name|name|name'>
+ %paramEntity;
+ <!-- comment -->
+ ]"""
+ self.check_events(["<!%s>" % inside], [
+ ("decl", inside),
+ ])
+
+ def test_doctype_decl_external(self):
+ inside = "DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01//EN'"
+ self.check_events("<!%s>" % inside, [
+ ("decl", inside),
+ ])
+
def test_underscore_in_attrname(self):
# SF bug #436621
***************
*** 133,136 ****
--- 173,186 ----
])
+ def test_bare_ampersands(self):
+ self.check_events("this text & contains & ampersands &", [
+ ("data", "this text & contains & ampersands &"),
+ ])
+
+ def test_bare_pointy_brackets(self):
+ self.check_events("this < text > contains < bare>pointy< brackets", [
+ ("data", "this < text > contains < bare>pointy< brackets"),
+ ])
+
def test_attr_syntax(self):
output = [
***************
*** 157,160 ****
--- 207,218 ----
])
+ def test_illegal_declarations(self):
+ s = 'abc<!spacer type="block" height="25">def'
+ self.check_events(s, [
+ ("data", "abc"),
+ ("unknown decl", 'spacer type="block" height="25"'),
+ ("data", "def"),
+ ])
+
def test_weird_starttags(self):
self.check_events("<a<a>", [
***************
*** 197,200 ****
--- 255,266 ----
])
+ def test_illegal_declarations(self):
+ s = 'abc<!spacer type="block" height="25">def'
+ self.check_events(s, [
+ ("data", "abc"),
+ ("unknown decl", 'spacer type="block" height="25"'),
+ ("data", "def"),
+ ])
+
# XXX These tests have been disabled by prefixing their names with
# an underscore. The first two exercise outstanding bugs in the
***************
*** 241,243 ****
! test_support.run_unittest(SGMLParserTestCase)
--- 307,314 ----
! def test_main():
! test_support.run_unittest(SGMLParserTestCase)
!
!
! if __name__ == "__main__":
! test_main()