[Python-checkins] CVS: python/dist/src/Lib/test test_htmlparser.py,1.4,1.5

Fred L. Drake fdrake@users.sourceforge.net
Tue, 04 Sep 2001 08:13:06 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv26027

Modified Files:
	test_htmlparser.py 
Log Message:
Enhanced the test for DOCTYPE declarations, added a test for dealing with
broken declaration-like things.


Index: test_htmlparser.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_htmlparser.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** test_htmlparser.py	2001/08/20 21:24:19	1.4
--- test_htmlparser.py	2001/09/04 15:13:04	1.5
***************
*** 61,64 ****
--- 61,67 ----
          self.append(("pi", data))
  
+     def unknown_decl(self, decl):
+         self.append(("unknown decl", decl))
+ 
  
  class EventCollectorExtra(EventCollector):
***************
*** 70,92 ****
  
  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)
          for s in source:
              parser.feed(s)
-         for c in self.epilogue:
-             parser.feed(c)
          parser.close()
          events = parser.get_events()
!         self.assertEqual(events,
!                          self.initial_events + events + self.final_events,
!                          "got events:\n" + pprint.pformat(events))
  
      def _run_check_extra(self, source, events):
--- 73,87 ----
  
  class TestCaseBase(unittest.TestCase):
  
!     def _run_check(self, source, expected_events, collector=EventCollector):
          parser = 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"
!                       "Expected:\n" + pprint.pformat(expected_events) +
!                       "\nReceived:\n" + pprint.pformat(events))
  
      def _run_check_extra(self, source, events):
***************
*** 145,149 ****
    <!ELEMENT html - O EMPTY>
    <!ATTLIST html
!       version CDATA #IMPLIED '4.0'>
    <!-- comment -->
  ]"""
--- 140,150 ----
    <!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 -->
  ]"""
***************
*** 200,203 ****
--- 201,212 ----
          self._run_check("""<a a.b='v' c:d=v e-f=v>""", [
              ("starttag", "a", [("a.b", "v"), ("c:d", "v"), ("e-f", "v")]),
+             ])
+ 
+     def test_illegal_declarations(self):
+         s = 'abc<!spacer type="block" height="25">def'
+         self._run_check(s, [
+             ("data", "abc"),
+             ("unknown decl", 'spacer type="block" height="25"'),
+             ("data", "def"),
              ])