[Python-checkins] CVS: python/dist/src/Lib/test test_pyexpat.py,1.3,1.4
Fred L. Drake
python-dev@python.org
Thu, 21 Sep 2000 13:32:15 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory slayer.i.sourceforge.net:/tmp/cvs-serv24345
Modified Files:
test_pyexpat.py
Log Message:
Revise the test case for pyexpat to avoid using asserts. Conform better
to the Python style guide, and remove unneeded imports.
Index: test_pyexpat.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_pyexpat.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** test_pyexpat.py 2000/06/27 00:37:25 1.3
--- test_pyexpat.py 2000/09/21 20:32:12 1.4
***************
*** 4,10 ****
# handler, are obscure and unhelpful.
- import sys, string
- import os
-
import pyexpat
--- 4,7 ----
***************
*** 17,21 ****
def CharacterDataHandler(self, data):
! data = string.strip(data)
if data:
print 'Character data:'
--- 14,18 ----
def CharacterDataHandler(self, data):
! data = data.strip()
if data:
print 'Character data:'
***************
*** 64,90 ****
out = Outputter()
parser = pyexpat.ParserCreate(namespace_separator='!')
# Test getting/setting returns_unicode
! parser.returns_unicode = 0 ; assert parser.returns_unicode == 0
! parser.returns_unicode = 1 ; assert parser.returns_unicode == 1
! parser.returns_unicode = 2 ; assert parser.returns_unicode == 1
! parser.returns_unicode = 0 ; assert parser.returns_unicode == 0
!
! HANDLER_NAMES = ['StartElementHandler', 'EndElementHandler',
! 'CharacterDataHandler', 'ProcessingInstructionHandler',
! 'UnparsedEntityDeclHandler', 'NotationDeclHandler',
! 'StartNamespaceDeclHandler', 'EndNamespaceDeclHandler',
! 'CommentHandler', 'StartCdataSectionHandler',
! 'EndCdataSectionHandler',
! 'DefaultHandler', 'DefaultHandlerExpand',
! #'NotStandaloneHandler',
! 'ExternalEntityRefHandler'
! ]
for name in HANDLER_NAMES:
! setattr(parser, name, getattr(out, name) )
! data = """<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
<?xml-stylesheet href="stylesheet.css"?>
<!-- comment data -->
--- 61,95 ----
+ def confirm(ok):
+ if ok:
+ print "OK."
+ else:
+ print "Not OK."
+
out = Outputter()
parser = pyexpat.ParserCreate(namespace_separator='!')
# Test getting/setting returns_unicode
! parser.returns_unicode = 0; confirm(parser.returns_unicode == 0)
! parser.returns_unicode = 1; confirm(parser.returns_unicode == 1)
! parser.returns_unicode = 2; confirm(parser.returns_unicode == 1)
! parser.returns_unicode = 0; confirm(parser.returns_unicode == 0)
!
! HANDLER_NAMES = [
! 'StartElementHandler', 'EndElementHandler',
! 'CharacterDataHandler', 'ProcessingInstructionHandler',
! 'UnparsedEntityDeclHandler', 'NotationDeclHandler',
! 'StartNamespaceDeclHandler', 'EndNamespaceDeclHandler',
! 'CommentHandler', 'StartCdataSectionHandler',
! 'EndCdataSectionHandler',
! 'DefaultHandler', 'DefaultHandlerExpand',
! #'NotStandaloneHandler',
! 'ExternalEntityRefHandler'
! ]
for name in HANDLER_NAMES:
! setattr(parser, name, getattr(out, name))
! data = '''\
! <?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
<?xml-stylesheet href="stylesheet.css"?>
<!-- comment data -->
***************
*** 105,109 ****
&external_entity;
</root>
! """
# Produce UTF-8 output
--- 110,114 ----
&external_entity;
</root>
! '''
# Produce UTF-8 output
***************
*** 112,116 ****
parser.Parse(data, 1)
except pyexpat.error:
! print '** Error', parser.ErrorCode, pyexpat.ErrorString( parser.ErrorCode)
print '** Line', parser.ErrorLineNumber
print '** Column', parser.ErrorColumnNumber
--- 117,121 ----
parser.Parse(data, 1)
except pyexpat.error:
! print '** Error', parser.ErrorCode, pyexpat.ErrorString(parser.ErrorCode)
print '** Line', parser.ErrorLineNumber
print '** Column', parser.ErrorColumnNumber
***************
*** 122,130 ****
for name in HANDLER_NAMES:
! setattr(parser, name, getattr(out, name) )
try:
parser.Parse(data, 1)
except pyexpat.error:
! print '** Error', parser.ErrorCode, pyexpat.ErrorString( parser.ErrorCode)
print '** Line', parser.ErrorLineNumber
print '** Column', parser.ErrorColumnNumber
--- 127,135 ----
for name in HANDLER_NAMES:
! setattr(parser, name, getattr(out, name))
try:
parser.Parse(data, 1)
except pyexpat.error:
! print '** Error', parser.ErrorCode, pyexpat.ErrorString(parser.ErrorCode)
print '** Line', parser.ErrorLineNumber
print '** Column', parser.ErrorColumnNumber
***************
*** 136,140 ****
for name in HANDLER_NAMES:
! setattr(parser, name, getattr(out, name) )
import StringIO
file = StringIO.StringIO(data)
--- 141,145 ----
for name in HANDLER_NAMES:
! setattr(parser, name, getattr(out, name))
import StringIO
file = StringIO.StringIO(data)
***************
*** 142,148 ****
parser.ParseFile(file)
except pyexpat.error:
! print '** Error', parser.ErrorCode, pyexpat.ErrorString( parser.ErrorCode)
print '** Line', parser.ErrorLineNumber
print '** Column', parser.ErrorColumnNumber
print '** Byte', parser.ErrorByteIndex
-
--- 147,152 ----
parser.ParseFile(file)
except pyexpat.error:
! print '** Error', parser.ErrorCode, pyexpat.ErrorString(parser.ErrorCode)
print '** Line', parser.ErrorLineNumber
print '** Column', parser.ErrorColumnNumber
print '** Byte', parser.ErrorByteIndex