From 8911ca3d70d97d46bbc7c7b77293ecc8c45d4c1f Mon Sep 17 00:00:00 2001 From: Fredrik Lundh Date: Fri, 16 Dec 2005 22:07:17 +0000 Subject: added encoding tests to ElementTree/cElementTree tests --- Lib/test/test_xml_etree.py | 25 ++++++++++++++++--------- Lib/test/test_xml_etree_c.py | 21 +++++++++++++++------ 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 8692b41..86052d7 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -6,6 +6,8 @@ import doctest, sys from test import test_support +from xmlcore.etree import ElementTree as ET + SAMPLE_XML = """ text @@ -59,8 +61,6 @@ def interface(): """ Test element tree interface. - >>> from xmlcore.etree import ElementTree as ET - >>> element = ET.Element("tag", key="value") >>> tree = ET.ElementTree(element) @@ -108,8 +108,6 @@ def find(): """ Test find methods (including xpath syntax). - >>> from xmlcore.etree import ElementTree as ET - >>> elem = ET.XML(SAMPLE_XML) >>> elem.find("tag").tag 'tag' @@ -176,8 +174,6 @@ def find(): def parseliteral(): r""" - >>> from xmlcore.etree import ElementTree as ET - >>> element = ET.XML("text") >>> ET.ElementTree(element).write(sys.stdout) text @@ -199,6 +195,19 @@ def parseliteral(): 'body' """ +def check_encoding(encoding): + """ + >>> check_encoding("ascii") + >>> check_encoding("us-ascii") + >>> check_encoding("iso-8859-1") + >>> check_encoding("iso-8859-15") + >>> check_encoding("cp437") + >>> check_encoding("mac-roman") + """ + ET.XML( + "" % encoding + ) + # # xinclude tests (samples from appendix C of the xinclude specification) @@ -273,15 +282,13 @@ def xinclude_loader(href, parse="xml", encoding=None): except KeyError: raise IOError("resource not found") if parse == "xml": - from xmlcore.etree.ElementTree import XML - return XML(data) + return ET.XML(data) return data def xinclude(): r""" Basic inclusion example (XInclude C.1) - >>> from xmlcore.etree import ElementTree as ET >>> from xmlcore.etree import ElementInclude >>> document = xinclude_loader("C1.xml") diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py index fcb6233..587ea99 100644 --- a/Lib/test/test_xml_etree_c.py +++ b/Lib/test/test_xml_etree_c.py @@ -4,6 +4,8 @@ import doctest, sys from test import test_support +from xmlcore.etree import cElementTree as ET + SAMPLE_XML = """ text @@ -55,8 +57,6 @@ def interface(): """ Test element tree interface. - >>> from xmlcore.etree import cElementTree as ET - >>> element = ET.Element("tag", key="value") >>> tree = ET.ElementTree(element) @@ -104,8 +104,6 @@ def find(): """ Test find methods (including xpath syntax). - >>> from xmlcore.etree import cElementTree as ET - >>> elem = ET.XML(SAMPLE_XML) >>> elem.find("tag").tag 'tag' @@ -172,8 +170,6 @@ def find(): def parseliteral(): r""" - >>> from xmlcore.etree import cElementTree as ET - >>> element = ET.XML("text") >>> ET.ElementTree(element).write(sys.stdout) text @@ -195,6 +191,19 @@ def parseliteral(): 'body' """ +def check_encoding(encoding): + """ + >>> check_encoding("ascii") + >>> check_encoding("us-ascii") + >>> check_encoding("iso-8859-1") + >>> check_encoding("iso-8859-15") + >>> check_encoding("cp437") + >>> check_encoding("mac-roman") + """ + ET.XML( + "" % encoding + ) + def test_main(): from test import test_xml_etree_c test_support.run_doctest(test_xml_etree_c, verbosity=True) -- cgit v0.12