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
278ba269
Kaydet (Commit)
278ba269
authored
Nis 02, 2015
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #2175: Added tests for xml.sax.saxutils.prepare_input_source().
Made test XML files non-ASCII.
üst
b1629141
aa9563c1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
10 deletions
+83
-10
test_minidom.py
Lib/test/test_minidom.py
+8
-2
test_sax.py
Lib/test/test_sax.py
+71
-5
test.xml
Lib/test/xmltestdata/test.xml
+2
-2
test.xml.out
Lib/test/xmltestdata/test.xml.out
+2
-1
No files found.
Lib/test/test_minidom.py
Dosyayı görüntüle @
278ba269
...
...
@@ -49,8 +49,14 @@ class MinidomTest(unittest.TestCase):
t
=
node
.
wholeText
self
.
confirm
(
t
==
s
,
"looking for
%
r, found
%
r"
%
(
s
,
t
))
def
testParseFromFile
(
self
):
with
open
(
tstfile
)
as
file
:
def
testParseFromBinaryFile
(
self
):
with
open
(
tstfile
,
'rb'
)
as
file
:
dom
=
parse
(
file
)
dom
.
unlink
()
self
.
confirm
(
isinstance
(
dom
,
Document
))
def
testParseFromTextFile
(
self
):
with
open
(
tstfile
,
'r'
,
encoding
=
'iso-8859-1'
)
as
file
:
dom
=
parse
(
file
)
dom
.
unlink
()
self
.
confirm
(
isinstance
(
dom
,
Document
))
...
...
Lib/test/test_sax.py
Dosyayı görüntüle @
278ba269
...
...
@@ -10,7 +10,7 @@ except SAXReaderNotAvailable:
# don't try to test this module if we cannot create a parser
raise
unittest
.
SkipTest
(
"no XML parsers available"
)
from
xml.sax.saxutils
import
XMLGenerator
,
escape
,
unescape
,
quoteattr
,
\
XMLFilterBase
XMLFilterBase
,
prepare_input_source
from
xml.sax.expatreader
import
create_parser
from
xml.sax.handler
import
feature_namespaces
from
xml.sax.xmlreader
import
InputSource
,
AttributesImpl
,
AttributesNSImpl
...
...
@@ -172,6 +172,60 @@ class SaxutilsTest(unittest.TestCase):
p
=
make_parser
([
'xml.parsers.no_such_parser'
])
class
PrepareInputSourceTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
file
=
support
.
TESTFN
with
open
(
self
.
file
,
"w"
)
as
tmp
:
tmp
.
write
(
"This was read from a file."
)
def
tearDown
(
self
):
support
.
unlink
(
self
.
file
)
def
make_byte_stream
(
self
):
return
BytesIO
(
b
"This is a byte stream."
)
def
checkContent
(
self
,
stream
,
content
):
self
.
assertIsNotNone
(
stream
)
self
.
assertEqual
(
stream
.
read
(),
content
)
stream
.
close
()
def
test_byte_stream
(
self
):
# If the source is an InputSource that does not have a character
# stream but does have a byte stream, use the byte stream.
src
=
InputSource
(
self
.
file
)
src
.
setByteStream
(
self
.
make_byte_stream
())
prep
=
prepare_input_source
(
src
)
self
.
assertIsNone
(
prep
.
getCharacterStream
())
self
.
checkContent
(
prep
.
getByteStream
(),
b
"This is a byte stream."
)
def
test_system_id
(
self
):
# If the source is an InputSource that has neither a character
# stream nor a byte stream, open the system ID.
src
=
InputSource
(
self
.
file
)
prep
=
prepare_input_source
(
src
)
self
.
assertIsNone
(
prep
.
getCharacterStream
())
self
.
checkContent
(
prep
.
getByteStream
(),
b
"This was read from a file."
)
def
test_string
(
self
):
# If the source is a string, use it as a system ID and open it.
prep
=
prepare_input_source
(
self
.
file
)
self
.
assertIsNone
(
prep
.
getCharacterStream
())
self
.
checkContent
(
prep
.
getByteStream
(),
b
"This was read from a file."
)
def
test_binary_file
(
self
):
# If the source is a binary file-like object, use it as a byte
# stream.
prep
=
prepare_input_source
(
self
.
make_byte_stream
())
self
.
assertIsNone
(
prep
.
getCharacterStream
())
self
.
checkContent
(
prep
.
getByteStream
(),
b
"This is a byte stream."
)
# ===== XMLGenerator
class
XmlgenTest
:
...
...
@@ -622,7 +676,7 @@ class ExpatReaderTest(XmlTestBase):
# ===== XMLReader support
def
test_expat_file
(
self
):
def
test_expat_
binary_
file
(
self
):
parser
=
create_parser
()
result
=
BytesIO
()
xmlgen
=
XMLGenerator
(
result
)
...
...
@@ -633,8 +687,19 @@ class ExpatReaderTest(XmlTestBase):
self
.
assertEqual
(
result
.
getvalue
(),
xml_test_out
)
def
test_expat_text_file
(
self
):
parser
=
create_parser
()
result
=
BytesIO
()
xmlgen
=
XMLGenerator
(
result
)
parser
.
setContentHandler
(
xmlgen
)
with
open
(
TEST_XMLFILE
,
'rt'
,
encoding
=
'iso-8859-1'
)
as
f
:
parser
.
parse
(
f
)
self
.
assertEqual
(
result
.
getvalue
(),
xml_test_out
)
@requires_nonascii_filenames
def
test_expat_file_nonascii
(
self
):
def
test_expat_
binary_
file_nonascii
(
self
):
fname
=
support
.
TESTFN_UNICODE
shutil
.
copyfile
(
TEST_XMLFILE
,
fname
)
self
.
addCleanup
(
support
.
unlink
,
fname
)
...
...
@@ -644,7 +709,7 @@ class ExpatReaderTest(XmlTestBase):
xmlgen
=
XMLGenerator
(
result
)
parser
.
setContentHandler
(
xmlgen
)
parser
.
parse
(
open
(
fname
))
parser
.
parse
(
open
(
fname
,
'rb'
))
self
.
assertEqual
(
result
.
getvalue
(),
xml_test_out
)
...
...
@@ -826,7 +891,7 @@ class ExpatReaderTest(XmlTestBase):
self
.
assertEqual
(
result
.
getvalue
(),
xml_test_out
)
def
test_expat_inpsource_stream
(
self
):
def
test_expat_inpsource_
byte_
stream
(
self
):
parser
=
create_parser
()
result
=
BytesIO
()
xmlgen
=
XMLGenerator
(
result
)
...
...
@@ -1018,6 +1083,7 @@ class XmlReaderTest(XmlTestBase):
def
test_main
():
run_unittest
(
MakeParserTest
,
SaxutilsTest
,
PrepareInputSourceTest
,
StringXmlgenTest
,
BytesXmlgenTest
,
WriterXmlgenTest
,
...
...
Lib/test/xmltestdata/test.xml
Dosyayı görüntüle @
278ba269
<?xml version="1.0"?>
<?xml version="1.0"
encoding="iso-8859-1"
?>
<HTML
xmlns:pp=
"http://www.isogen.com/paul/post-processor"
>
<TITLE>
Introduction to XSL
</TITLE>
<H1>
Introduction to XSL
</H1>
...
...
@@ -110,6 +110,6 @@
</UL>
</HTML>
Lib/test/xmltestdata/test.xml.out
Dosyayı görüntüle @
278ba269
...
...
@@ -110,6 +110,6 @@
</UL>
</HTML>
\ No newline at end of file
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