mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Revise the test case for pyexpat to avoid using asserts. Conform better
to the Python style guide, and remove unneeded imports.
This commit is contained in:
parent
9e79a25b8a
commit
265a804af2
2 changed files with 35 additions and 27 deletions
|
@ -1,4 +1,8 @@
|
|||
test_pyexpat
|
||||
OK.
|
||||
OK.
|
||||
OK.
|
||||
OK.
|
||||
PI:
|
||||
'xml-stylesheet' 'href="stylesheet.css"'
|
||||
Comment:
|
||||
|
|
|
@ -3,9 +3,6 @@
|
|||
# XXX TypeErrors on calling handlers, or on bad return values from a
|
||||
# handler, are obscure and unhelpful.
|
||||
|
||||
import sys, string
|
||||
import os
|
||||
|
||||
import pyexpat
|
||||
|
||||
class Outputter:
|
||||
|
@ -16,7 +13,7 @@ class Outputter:
|
|||
print 'End element:\n\t', repr(name)
|
||||
|
||||
def CharacterDataHandler(self, data):
|
||||
data = string.strip(data)
|
||||
data = data.strip()
|
||||
if data:
|
||||
print 'Character data:'
|
||||
print '\t', repr(data)
|
||||
|
@ -63,16 +60,23 @@ class Outputter:
|
|||
pass
|
||||
|
||||
|
||||
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 ; 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
|
||||
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',
|
||||
HANDLER_NAMES = [
|
||||
'StartElementHandler', 'EndElementHandler',
|
||||
'CharacterDataHandler', 'ProcessingInstructionHandler',
|
||||
'UnparsedEntityDeclHandler', 'NotationDeclHandler',
|
||||
'StartNamespaceDeclHandler', 'EndNamespaceDeclHandler',
|
||||
|
@ -85,7 +89,8 @@ HANDLER_NAMES = ['StartElementHandler', 'EndElementHandler',
|
|||
for name in HANDLER_NAMES:
|
||||
setattr(parser, name, getattr(out, name))
|
||||
|
||||
data = """<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
|
||||
data = '''\
|
||||
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
|
||||
<?xml-stylesheet href="stylesheet.css"?>
|
||||
<!-- comment data -->
|
||||
<!DOCTYPE quotations SYSTEM "quotations.dtd" [
|
||||
|
@ -104,7 +109,7 @@ data = """<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
|
|||
<sub2><![CDATA[contents of CDATA section]]></sub2>
|
||||
&external_entity;
|
||||
</root>
|
||||
"""
|
||||
'''
|
||||
|
||||
# Produce UTF-8 output
|
||||
parser.returns_unicode = 0
|
||||
|
@ -145,4 +150,3 @@ except pyexpat.error:
|
|||
print '** Line', parser.ErrorLineNumber
|
||||
print '** Column', parser.ErrorColumnNumber
|
||||
print '** Byte', parser.ErrorByteIndex
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue