Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
265a804a
Kaydet (Commit)
265a804a
authored
Eyl 21, 2000
tarafından
Fred Drake
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Revise the test case for pyexpat to avoid using asserts. Conform better
to the Python style guide, and remove unneeded imports.
üst
9e79a25b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
28 deletions
+36
-28
test_pyexpat
Lib/test/output/test_pyexpat
+4
-0
test_pyexpat.py
Lib/test/test_pyexpat.py
+32
-28
No files found.
Lib/test/output/test_pyexpat
Dosyayı görüntüle @
265a804a
test_pyexpat
OK.
OK.
OK.
OK.
PI:
'xml-stylesheet' 'href="stylesheet.css"'
Comment:
...
...
Lib/test/test_pyexpat.py
Dosyayı görüntüle @
265a804a
...
...
@@ -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,29 +60,37 @@ 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
HANDLER_NAMES
=
[
'StartElementHandler'
,
'EndElementHandler'
,
'CharacterDataHandler'
,
'ProcessingInstructionHandler'
,
'UnparsedEntityDeclHandler'
,
'NotationDeclHandler'
,
'StartNamespaceDeclHandler'
,
'EndNamespaceDeclHandler'
,
'CommentHandler'
,
'StartCdataSectionHandler'
,
'EndCdataSectionHandler'
,
'DefaultHandler'
,
'DefaultHandlerExpand'
,
#'NotStandaloneHandler',
'ExternalEntityRefHandler'
]
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
)
)
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,14 +109,14 @@ 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
try
:
parser
.
Parse
(
data
,
1
)
except
pyexpat
.
error
:
print
'** Error'
,
parser
.
ErrorCode
,
pyexpat
.
ErrorString
(
parser
.
ErrorCode
)
print
'** Error'
,
parser
.
ErrorCode
,
pyexpat
.
ErrorString
(
parser
.
ErrorCode
)
print
'** Line'
,
parser
.
ErrorLineNumber
print
'** Column'
,
parser
.
ErrorColumnNumber
print
'** Byte'
,
parser
.
ErrorByteIndex
...
...
@@ -121,11 +126,11 @@ parser = pyexpat.ParserCreate(namespace_separator='!')
parser
.
returns_unicode
=
1
for
name
in
HANDLER_NAMES
:
setattr
(
parser
,
name
,
getattr
(
out
,
name
)
)
setattr
(
parser
,
name
,
getattr
(
out
,
name
))
try
:
parser
.
Parse
(
data
,
1
)
except
pyexpat
.
error
:
print
'** Error'
,
parser
.
ErrorCode
,
pyexpat
.
ErrorString
(
parser
.
ErrorCode
)
print
'** Error'
,
parser
.
ErrorCode
,
pyexpat
.
ErrorString
(
parser
.
ErrorCode
)
print
'** Line'
,
parser
.
ErrorLineNumber
print
'** Column'
,
parser
.
ErrorColumnNumber
print
'** Byte'
,
parser
.
ErrorByteIndex
...
...
@@ -135,14 +140,13 @@ parser = pyexpat.ParserCreate(namespace_separator='!')
parser
.
returns_unicode
=
1
for
name
in
HANDLER_NAMES
:
setattr
(
parser
,
name
,
getattr
(
out
,
name
)
)
setattr
(
parser
,
name
,
getattr
(
out
,
name
))
import
StringIO
file
=
StringIO
.
StringIO
(
data
)
try
:
parser
.
ParseFile
(
file
)
except
pyexpat
.
error
:
print
'** Error'
,
parser
.
ErrorCode
,
pyexpat
.
ErrorString
(
parser
.
ErrorCode
)
print
'** Error'
,
parser
.
ErrorCode
,
pyexpat
.
ErrorString
(
parser
.
ErrorCode
)
print
'** Line'
,
parser
.
ErrorLineNumber
print
'** Column'
,
parser
.
ErrorColumnNumber
print
'** Byte'
,
parser
.
ErrorByteIndex
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment