Skip to content

Commit 8911ca3

Browse files
author
Fredrik Lundh
committed
added encoding tests to ElementTree/cElementTree tests
1 parent 6d52b55 commit 8911ca3

2 files changed

Lines changed: 31 additions & 15 deletions

File tree

Lib/test/test_xml_etree.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
from test import test_support
88

9+
from xmlcore.etree import ElementTree as ET
10+
911
SAMPLE_XML = """
1012
<body>
1113
<tag>text</tag>
@@ -59,8 +61,6 @@ def interface():
5961
"""
6062
Test element tree interface.
6163
62-
>>> from xmlcore.etree import ElementTree as ET
63-
6464
>>> element = ET.Element("tag", key="value")
6565
>>> tree = ET.ElementTree(element)
6666
@@ -108,8 +108,6 @@ def find():
108108
"""
109109
Test find methods (including xpath syntax).
110110
111-
>>> from xmlcore.etree import ElementTree as ET
112-
113111
>>> elem = ET.XML(SAMPLE_XML)
114112
>>> elem.find("tag").tag
115113
'tag'
@@ -176,8 +174,6 @@ def find():
176174
def parseliteral():
177175
r"""
178176
179-
>>> from xmlcore.etree import ElementTree as ET
180-
181177
>>> element = ET.XML("<html><body>text</body></html>")
182178
>>> ET.ElementTree(element).write(sys.stdout)
183179
<html><body>text</body></html>
@@ -199,6 +195,19 @@ def parseliteral():
199195
'body'
200196
"""
201197

198+
def check_encoding(encoding):
199+
"""
200+
>>> check_encoding("ascii")
201+
>>> check_encoding("us-ascii")
202+
>>> check_encoding("iso-8859-1")
203+
>>> check_encoding("iso-8859-15")
204+
>>> check_encoding("cp437")
205+
>>> check_encoding("mac-roman")
206+
"""
207+
ET.XML(
208+
"<?xml version='1.0' encoding='%s'?><xml />" % encoding
209+
)
210+
202211
#
203212
# xinclude tests (samples from appendix C of the xinclude specification)
204213

@@ -273,15 +282,13 @@ def xinclude_loader(href, parse="xml", encoding=None):
273282
except KeyError:
274283
raise IOError("resource not found")
275284
if parse == "xml":
276-
from xmlcore.etree.ElementTree import XML
277-
return XML(data)
285+
return ET.XML(data)
278286
return data
279287

280288
def xinclude():
281289
r"""
282290
Basic inclusion example (XInclude C.1)
283291
284-
>>> from xmlcore.etree import ElementTree as ET
285292
>>> from xmlcore.etree import ElementInclude
286293
287294
>>> document = xinclude_loader("C1.xml")

Lib/test/test_xml_etree_c.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from test import test_support
66

7+
from xmlcore.etree import cElementTree as ET
8+
79
SAMPLE_XML = """
810
<body>
911
<tag>text</tag>
@@ -55,8 +57,6 @@ def interface():
5557
"""
5658
Test element tree interface.
5759
58-
>>> from xmlcore.etree import cElementTree as ET
59-
6060
>>> element = ET.Element("tag", key="value")
6161
>>> tree = ET.ElementTree(element)
6262
@@ -104,8 +104,6 @@ def find():
104104
"""
105105
Test find methods (including xpath syntax).
106106
107-
>>> from xmlcore.etree import cElementTree as ET
108-
109107
>>> elem = ET.XML(SAMPLE_XML)
110108
>>> elem.find("tag").tag
111109
'tag'
@@ -172,8 +170,6 @@ def find():
172170
def parseliteral():
173171
r"""
174172
175-
>>> from xmlcore.etree import cElementTree as ET
176-
177173
>>> element = ET.XML("<html><body>text</body></html>")
178174
>>> ET.ElementTree(element).write(sys.stdout)
179175
<html><body>text</body></html>
@@ -195,6 +191,19 @@ def parseliteral():
195191
'body'
196192
"""
197193

194+
def check_encoding(encoding):
195+
"""
196+
>>> check_encoding("ascii")
197+
>>> check_encoding("us-ascii")
198+
>>> check_encoding("iso-8859-1")
199+
>>> check_encoding("iso-8859-15")
200+
>>> check_encoding("cp437")
201+
>>> check_encoding("mac-roman")
202+
"""
203+
ET.XML(
204+
"<?xml version='1.0' encoding='%s'?><xml />" % encoding
205+
)
206+
198207
def test_main():
199208
from test import test_xml_etree_c
200209
test_support.run_doctest(test_xml_etree_c, verbosity=True)

0 commit comments

Comments
 (0)