\xe3'), 'latin-1'),
+ b"\n"
+ b"\xe3?>")
+
+ def test_html_empty_elems_serialization(self):
+ # issue 15970
+ # from http://www.w3.org/TR/html401/index/elements.html
+ for element in ['AREA', 'BASE', 'BASEFONT', 'BR', 'COL', 'FRAME', 'HR',
+ 'IMG', 'INPUT', 'ISINDEX', 'LINK', 'META', 'PARAM']:
+ for elem in [element, element.lower()]:
+ expected = '<%s>' % elem
+ serialized = serialize(ET.XML('<%s />' % elem), method='html')
+ self.assertEqual(serialized, expected)
+ serialized = serialize(ET.XML('<%s>%s>' % (elem,elem)),
+ method='html')
+ self.assertEqual(serialized, expected)
+
#
# xinclude tests (samples from appendix C of the xinclude specification)
@@ -1120,79 +986,6 @@ XINCLUDE["default.xml"] = """\
""".format(html.escape(SIMPLE_XMLFILE, True))
-
-def xinclude_loader(href, parse="xml", encoding=None):
- try:
- data = XINCLUDE[href]
- except KeyError:
- raise OSError("resource not found")
- if parse == "xml":
- data = ET.XML(data)
- return data
-
-def xinclude():
- r"""
- Basic inclusion example (XInclude C.1)
-
- >>> from xml.etree import ElementInclude
-
- >>> document = xinclude_loader("C1.xml")
- >>> ElementInclude.include(document, xinclude_loader)
- >>> print(serialize(document)) # C1
-
- 120 Mz is adequate for an average home user.
-
- The opinions represented herein represent those of the individual
- and should not be interpreted as official policy endorsed by this
- organization.
-
-
-
- Textual inclusion example (XInclude C.2)
-
- >>> document = xinclude_loader("C2.xml")
- >>> ElementInclude.include(document, xinclude_loader)
- >>> print(serialize(document)) # C2
-
- This document has been accessed
- 324387 times.
-
-
- Textual inclusion after sibling element (based on modified XInclude C.2)
-
- >>> document = xinclude_loader("C2b.xml")
- >>> ElementInclude.include(document, xinclude_loader)
- >>> print(serialize(document)) # C2b
-
- This document has been accessed
- 324387 times.
-
-
- Textual inclusion of XML example (XInclude C.3)
-
- >>> document = xinclude_loader("C3.xml")
- >>> ElementInclude.include(document, xinclude_loader)
- >>> print(serialize(document)) # C3
-
- The following is the source of the "data.xml" resource:
- <?xml version='1.0'?>
- <data>
- <item><![CDATA[Brooks & Shields]]></item>
- </data>
-
-
-
- Fallback example (XInclude C.5)
- Note! Fallback support is not yet implemented
-
- >>> document = xinclude_loader("C5.xml")
- >>> ElementInclude.include(document, xinclude_loader)
- Traceback (most recent call last):
- OSError: resource not found
- >>> # print(serialize(document)) # C5
- """
-
-
#
# badly formatted xi:include tags
@@ -1213,410 +1006,412 @@ XINCLUDE_BAD["B2.xml"] = """\
"""
-def xinclude_failures():
- r"""
- Test failure to locate included XML file.
+class XIncludeTest(unittest.TestCase):
- >>> from xml.etree import ElementInclude
+ def xinclude_loader(self, href, parse="xml", encoding=None):
+ try:
+ data = XINCLUDE[href]
+ except KeyError:
+ raise OSError("resource not found")
+ if parse == "xml":
+ data = ET.XML(data)
+ return data
- >>> def none_loader(href, parser, encoding=None):
- ... return None
+ def none_loader(self, href, parser, encoding=None):
+ return None
- >>> document = ET.XML(XINCLUDE["C1.xml"])
- >>> ElementInclude.include(document, loader=none_loader)
- Traceback (most recent call last):
- xml.etree.ElementInclude.FatalIncludeError: cannot load 'disclaimer.xml' as 'xml'
+ def _my_loader(self, href, parse):
+ # Used to avoid a test-dependency problem where the default loader
+ # of ElementInclude uses the pyET parser for cET tests.
+ if parse == 'xml':
+ with open(href, 'rb') as f:
+ return ET.parse(f).getroot()
+ else:
+ return None
- Test failure to locate included text file.
+ def test_xinclude_default(self):
+ from xml.etree import ElementInclude
+ doc = self.xinclude_loader('default.xml')
+ ElementInclude.include(doc, self._my_loader)
+ self.assertEqual(serialize(doc),
+ '\n'
+ ' Example.
\n'
+ ' \n'
+ ' text\n'
+ ' texttail\n'
+ ' \n'
+ '\n'
+ '')
- >>> document = ET.XML(XINCLUDE["C2.xml"])
- >>> ElementInclude.include(document, loader=none_loader)
- Traceback (most recent call last):
- xml.etree.ElementInclude.FatalIncludeError: cannot load 'count.txt' as 'text'
+ def test_xinclude(self):
+ from xml.etree import ElementInclude
- Test bad parse type.
+ # Basic inclusion example (XInclude C.1)
+ document = self.xinclude_loader("C1.xml")
+ ElementInclude.include(document, self.xinclude_loader)
+ self.assertEqual(serialize(document),
+ '\n'
+ ' 120 Mz is adequate for an average home user.
\n'
+ ' \n'
+ ' The opinions represented herein represent those of the individual\n'
+ ' and should not be interpreted as official policy endorsed by this\n'
+ ' organization.
\n'
+ '\n'
+ '') # C1
- >>> document = ET.XML(XINCLUDE_BAD["B1.xml"])
- >>> ElementInclude.include(document, loader=none_loader)
- Traceback (most recent call last):
- xml.etree.ElementInclude.FatalIncludeError: unknown parse type in xi:include tag ('BAD_TYPE')
+ # Textual inclusion example (XInclude C.2)
+ document = self.xinclude_loader("C2.xml")
+ ElementInclude.include(document, self.xinclude_loader)
+ self.assertEqual(serialize(document),
+ '\n'
+ ' This document has been accessed\n'
+ ' 324387 times.
\n'
+ '') # C2
- Test xi:fallback outside xi:include.
+ # Textual inclusion after sibling element (based on modified XInclude C.2)
+ document = self.xinclude_loader("C2b.xml")
+ ElementInclude.include(document, self.xinclude_loader)
+ self.assertEqual(serialize(document),
+ '\n'
+ ' This document has been accessed\n'
+ ' 324387 times.
\n'
+ '') # C2b
- >>> document = ET.XML(XINCLUDE_BAD["B2.xml"])
- >>> ElementInclude.include(document, loader=none_loader)
- Traceback (most recent call last):
- xml.etree.ElementInclude.FatalIncludeError: xi:fallback tag must be child of xi:include ('{http://www.w3.org/2001/XInclude}fallback')
- """
+ # Textual inclusion of XML example (XInclude C.3)
+ document = self.xinclude_loader("C3.xml")
+ ElementInclude.include(document, self.xinclude_loader)
+ self.assertEqual(serialize(document),
+ '\n'
+ ' The following is the source of the "data.xml" resource:
\n'
+ " <?xml version='1.0'?>\n"
+ '<data>\n'
+ ' <item><![CDATA[Brooks & Shields]]></item>\n'
+ '</data>\n'
+ '\n'
+ '') # C3
+
+ # Fallback example (XInclude C.5)
+ # Note! Fallback support is not yet implemented
+ document = self.xinclude_loader("C5.xml")
+ with self.assertRaises(OSError) as cm:
+ ElementInclude.include(document, self.xinclude_loader)
+ self.assertEqual(str(cm.exception), 'resource not found')
+ self.assertEqual(serialize(document),
+ '\n'
+ '
\n'
+ ' \n'
+ ' \n'
+ ' Report error\n'
+ ' \n'
+ ' \n'
+ ' \n'
+ '
') # C5
+
+ def test_xinclude_failures(self):
+ from xml.etree import ElementInclude
+
+ # Test failure to locate included XML file.
+ document = ET.XML(XINCLUDE["C1.xml"])
+ with self.assertRaises(ElementInclude.FatalIncludeError) as cm:
+ ElementInclude.include(document, loader=self.none_loader)
+ self.assertEqual(str(cm.exception),
+ "cannot load 'disclaimer.xml' as 'xml'")
+
+ # Test failure to locate included text file.
+ document = ET.XML(XINCLUDE["C2.xml"])
+ with self.assertRaises(ElementInclude.FatalIncludeError) as cm:
+ ElementInclude.include(document, loader=self.none_loader)
+ self.assertEqual(str(cm.exception),
+ "cannot load 'count.txt' as 'text'")
+
+ # Test bad parse type.
+ document = ET.XML(XINCLUDE_BAD["B1.xml"])
+ with self.assertRaises(ElementInclude.FatalIncludeError) as cm:
+ ElementInclude.include(document, loader=self.none_loader)
+ self.assertEqual(str(cm.exception),
+ "unknown parse type in xi:include tag ('BAD_TYPE')")
+
+ # Test xi:fallback outside xi:include.
+ document = ET.XML(XINCLUDE_BAD["B2.xml"])
+ with self.assertRaises(ElementInclude.FatalIncludeError) as cm:
+ ElementInclude.include(document, loader=self.none_loader)
+ self.assertEqual(str(cm.exception),
+ "xi:fallback tag must be child of xi:include "
+ "('{http://www.w3.org/2001/XInclude}fallback')")
# --------------------------------------------------------------------
# reported bugs
-def bug_xmltoolkit21():
- """
+class BugsTest(unittest.TestCase):
- marshaller gives obscure errors for non-string values
+ def test_bug_xmltoolkit21(self):
+ # marshaller gives obscure errors for non-string values
- >>> elem = ET.Element(123)
- >>> serialize(elem) # tag
- Traceback (most recent call last):
- TypeError: cannot serialize 123 (type int)
- >>> elem = ET.Element("elem")
- >>> elem.text = 123
- >>> serialize(elem) # text
- Traceback (most recent call last):
- TypeError: cannot serialize 123 (type int)
- >>> elem = ET.Element("elem")
- >>> elem.tail = 123
- >>> serialize(elem) # tail
- Traceback (most recent call last):
- TypeError: cannot serialize 123 (type int)
- >>> elem = ET.Element("elem")
- >>> elem.set(123, "123")
- >>> serialize(elem) # attribute key
- Traceback (most recent call last):
- TypeError: cannot serialize 123 (type int)
- >>> elem = ET.Element("elem")
- >>> elem.set("123", 123)
- >>> serialize(elem) # attribute value
- Traceback (most recent call last):
- TypeError: cannot serialize 123 (type int)
+ def check(elem):
+ with self.assertRaises(TypeError) as cm:
+ serialize(elem)
+ self.assertEqual(str(cm.exception),
+ 'cannot serialize 123 (type int)')
- """
+ elem = ET.Element(123)
+ check(elem) # tag
-def bug_xmltoolkit25():
- """
+ elem = ET.Element("elem")
+ elem.text = 123
+ check(elem) # text
- typo in ElementTree.findtext
+ elem = ET.Element("elem")
+ elem.tail = 123
+ check(elem) # tail
- >>> elem = ET.XML(SAMPLE_XML)
- >>> tree = ET.ElementTree(elem)
- >>> tree.findtext("tag")
- 'text'
- >>> tree.findtext("section/tag")
- 'subtext'
+ elem = ET.Element("elem")
+ elem.set(123, "123")
+ check(elem) # attribute key
- """
+ elem = ET.Element("elem")
+ elem.set("123", 123)
+ check(elem) # attribute value
-def bug_xmltoolkit28():
- """
+ def test_bug_xmltoolkit25(self):
+ # typo in ElementTree.findtext
- .//tag causes exceptions
+ elem = ET.XML(SAMPLE_XML)
+ tree = ET.ElementTree(elem)
+ self.assertEqual(tree.findtext("tag"), 'text')
+ self.assertEqual(tree.findtext("section/tag"), 'subtext')
- >>> tree = ET.XML("")
- >>> summarize_list(tree.findall(".//thead"))
- []
- >>> summarize_list(tree.findall(".//tbody"))
- ['tbody']
+ def test_bug_xmltoolkit28(self):
+ # .//tag causes exceptions
- """
+ tree = ET.XML("")
+ self.assertEqual(summarize_list(tree.findall(".//thead")), [])
+ self.assertEqual(summarize_list(tree.findall(".//tbody")), ['tbody'])
-def bug_xmltoolkitX1():
- """
+ def test_bug_xmltoolkitX1(self):
+ # dump() doesn't flush the output buffer
- dump() doesn't flush the output buffer
+ tree = ET.XML("")
+ with support.captured_stdout() as stdout:
+ ET.dump(tree)
+ self.assertEqual(stdout.getvalue(), '\n')
- >>> tree = ET.XML("")
- >>> ET.dump(tree); print("tail")
-
- tail
+ def test_bug_xmltoolkit39(self):
+ # non-ascii element and attribute names doesn't work
- """
+ tree = ET.XML(b"")
+ self.assertEqual(ET.tostring(tree, "utf-8"), b'')
-def bug_xmltoolkit39():
- """
+ tree = ET.XML(b""
+ b"")
+ self.assertEqual(tree.attrib, {'\xe4ttr': 'v\xe4lue'})
+ self.assertEqual(ET.tostring(tree, "utf-8"),
+ b'')
- non-ascii element and attribute names doesn't work
+ tree = ET.XML(b""
+ b'text')
+ self.assertEqual(ET.tostring(tree, "utf-8"),
+ b'text')
- >>> tree = ET.XML(b"")
- >>> ET.tostring(tree, "utf-8")
- b''
+ tree = ET.Element("t\u00e4g")
+ self.assertEqual(ET.tostring(tree, "utf-8"), b'')
- >>> tree = ET.XML(b"")
- >>> tree.attrib
- {'\\xe4ttr': 'v\\xe4lue'}
- >>> ET.tostring(tree, "utf-8")
- b''
+ tree = ET.Element("tag")
+ tree.set("\u00e4ttr", "v\u00e4lue")
+ self.assertEqual(ET.tostring(tree, "utf-8"),
+ b'')
- >>> tree = ET.XML(b"text")
- >>> ET.tostring(tree, "utf-8")
- b'text'
+ def test_bug_xmltoolkit54(self):
+ # problems handling internally defined entities
- >>> tree = ET.Element("t\u00e4g")
- >>> ET.tostring(tree, "utf-8")
- b''
+ e = ET.XML("]>"
+ '&ldots;')
+ self.assertEqual(serialize(e, encoding="us-ascii"),
+ b'舰')
+ self.assertEqual(serialize(e), '\u8230')
- >>> tree = ET.Element("tag")
- >>> tree.set("\u00e4ttr", "v\u00e4lue")
- >>> ET.tostring(tree, "utf-8")
- b''
+ def test_bug_xmltoolkit55(self):
+ # make sure we're reporting the first error, not the last
- """
+ with self.assertRaises(ET.ParseError) as cm:
+ ET.XML(b""
+ b'&ldots;&ndots;&rdots;')
+ self.assertEqual(str(cm.exception),
+ 'undefined entity &ldots;: line 1, column 36')
-def bug_xmltoolkit54():
- """
+ def test_bug_xmltoolkit60(self):
+ # Handle crash in stream source.
- problems handling internally defined entities
+ class ExceptionFile:
+ def read(self, x):
+ raise OSError
- >>> e = ET.XML("]>&ldots;")
- >>> serialize(e, encoding="us-ascii")
- b'舰'
- >>> serialize(e)
- '\u8230'
+ self.assertRaises(OSError, ET.parse, ExceptionFile())
- """
+ def test_bug_xmltoolkit62(self):
+ # Don't crash when using custom entities.
-def bug_xmltoolkit55():
- """
-
- make sure we're reporting the first error, not the last
-
- >>> normalize_exception(ET.XML, b"&ldots;&ndots;&rdots;")
- Traceback (most recent call last):
- ParseError: undefined entity &ldots;: line 1, column 36
-
- """
-
-class ExceptionFile:
- def read(self, x):
- raise OSError
-
-def xmltoolkit60():
- """
-
- Handle crash in stream source.
- >>> tree = ET.parse(ExceptionFile())
- Traceback (most recent call last):
- OSError
-
- """
-
-XMLTOOLKIT62_DOC = """
+ ENTITIES = {'rsquo': '\u2019', 'lsquo': '\u2018'}
+ parser = ET.XMLTreeBuilder()
+ parser.entity.update(ENTITIES)
+ parser.feed("""
A new cultivar of Begonia plant named ‘BCT9801BEG’.
-"""
+""")
+ t = parser.close()
+ self.assertEqual(t.find('.//paragraph').text,
+ 'A new cultivar of Begonia plant named \u2018BCT9801BEG\u2019.')
+ def test_bug_xmltoolkit63(self):
+ # Check reference leak.
+ def xmltoolkit63():
+ tree = ET.TreeBuilder()
+ tree.start("tag", {})
+ tree.data("text")
+ tree.end("tag")
-def xmltoolkit62():
- """
+ xmltoolkit63()
+ count = sys.getrefcount(None)
+ for i in range(1000):
+ xmltoolkit63()
+ self.assertEqual(sys.getrefcount(None), count)
- Don't crash when using custom entities.
+ def test_bug_200708_newline(self):
+ # Preserve newlines in attributes.
- >>> xmltoolkit62()
- 'A new cultivar of Begonia plant named \u2018BCT9801BEG\u2019.'
+ e = ET.Element('SomeTag', text="def _f():\n return 3\n")
+ self.assertEqual(ET.tostring(e),
+ b'')
+ self.assertEqual(ET.XML(ET.tostring(e)).get("text"),
+ 'def _f():\n return 3\n')
+ self.assertEqual(ET.tostring(ET.XML(ET.tostring(e))),
+ b'')
- """
- ENTITIES = {'rsquo': '\u2019', 'lsquo': '\u2018'}
- parser = ET.XMLTreeBuilder()
- parser.entity.update(ENTITIES)
- parser.feed(XMLTOOLKIT62_DOC)
- t = parser.close()
- return t.find('.//paragraph').text
+ def test_bug_200708_close(self):
+ # Test default builder.
+ parser = ET.XMLParser() # default
+ parser.feed("some text")
+ self.assertEqual(parser.close().tag, 'element')
-def xmltoolkit63():
- """
+ # Test custom builder.
+ class EchoTarget:
+ def close(self):
+ return ET.Element("element") # simulate root
+ parser = ET.XMLParser(EchoTarget())
+ parser.feed("some text")
+ self.assertEqual(parser.close().tag, 'element')
- Check reference leak.
- >>> xmltoolkit63()
- >>> count = sys.getrefcount(None)
- >>> for i in range(1000):
- ... xmltoolkit63()
- >>> sys.getrefcount(None) - count
- 0
+ def test_bug_200709_default_namespace(self):
+ e = ET.Element("{default}elem")
+ s = ET.SubElement(e, "{default}elem")
+ self.assertEqual(serialize(e, default_namespace="default"), # 1
+ '')
- """
- tree = ET.TreeBuilder()
- tree.start("tag", {})
- tree.data("text")
- tree.end("tag")
+ e = ET.Element("{default}elem")
+ s = ET.SubElement(e, "{default}elem")
+ s = ET.SubElement(e, "{not-default}elem")
+ self.assertEqual(serialize(e, default_namespace="default"), # 2
+ ''
+ ''
+ ''
+ '')
-# --------------------------------------------------------------------
+ e = ET.Element("{default}elem")
+ s = ET.SubElement(e, "{default}elem")
+ s = ET.SubElement(e, "elem") # unprefixed name
+ with self.assertRaises(ValueError) as cm:
+ serialize(e, default_namespace="default") # 3
+ self.assertEqual(str(cm.exception),
+ 'cannot use non-qualified names with default_namespace option')
+ def test_bug_200709_register_namespace(self):
+ e = ET.Element("{http://namespace.invalid/does/not/exist/}title")
+ self.assertEqual(ET.tostring(e),
+ b'')
+ ET.register_namespace("foo", "http://namespace.invalid/does/not/exist/")
+ e = ET.Element("{http://namespace.invalid/does/not/exist/}title")
+ self.assertEqual(ET.tostring(e),
+ b'')
-def bug_200708_newline():
- r"""
+ # And the Dublin Core namespace is in the default list:
- Preserve newlines in attributes.
+ e = ET.Element("{http://purl.org/dc/elements/1.1/}title")
+ self.assertEqual(ET.tostring(e),
+ b'')
- >>> e = ET.Element('SomeTag', text="def _f():\n return 3\n")
- >>> ET.tostring(e)
- b''
- >>> ET.XML(ET.tostring(e)).get("text")
- 'def _f():\n return 3\n'
- >>> ET.tostring(ET.XML(ET.tostring(e)))
- b''
+ def test_bug_200709_element_comment(self):
+ # Not sure if this can be fixed, really (since the serializer needs
+ # ET.Comment, not cET.comment).
- """
+ a = ET.Element('a')
+ a.append(ET.Comment('foo'))
+ self.assertEqual(a[0].tag, ET.Comment)
-def bug_200708_close():
- """
+ a = ET.Element('a')
+ a.append(ET.PI('foo'))
+ self.assertEqual(a[0].tag, ET.PI)
- Test default builder.
- >>> parser = ET.XMLParser() # default
- >>> parser.feed("some text")
- >>> summarize(parser.close())
- 'element'
+ def test_bug_200709_element_insert(self):
+ a = ET.Element('a')
+ b = ET.SubElement(a, 'b')
+ c = ET.SubElement(a, 'c')
+ d = ET.Element('d')
+ a.insert(0, d)
+ self.assertEqual(summarize_list(a), ['d', 'b', 'c'])
+ a.insert(-1, d)
+ self.assertEqual(summarize_list(a), ['d', 'b', 'd', 'c'])
- Test custom builder.
- >>> class EchoTarget:
- ... def close(self):
- ... return ET.Element("element") # simulate root
- >>> parser = ET.XMLParser(EchoTarget())
- >>> parser.feed("some text")
- >>> summarize(parser.close())
- 'element'
+ def test_bug_200709_iter_comment(self):
+ a = ET.Element('a')
+ b = ET.SubElement(a, 'b')
+ comment_b = ET.Comment("TEST-b")
+ b.append(comment_b)
+ self.assertEqual(summarize_list(a.iter(ET.Comment)), [ET.Comment])
- """
+ # --------------------------------------------------------------------
+ # reported on bugs.python.org
-def bug_200709_default_namespace():
- """
+ def test_bug_1534630(self):
+ bob = ET.TreeBuilder()
+ e = bob.data("data")
+ e = bob.start("tag", {})
+ e = bob.end("tag")
+ e = bob.close()
+ self.assertEqual(serialize(e), '')
- >>> e = ET.Element("{default}elem")
- >>> s = ET.SubElement(e, "{default}elem")
- >>> serialize(e, default_namespace="default") # 1
- ''
+ def test_issue6233(self):
+ e = ET.XML(b""
+ b't\xc3\xa3g')
+ self.assertEqual(ET.tostring(e, 'ascii'),
+ b"\n"
+ b'tãg')
+ e = ET.XML(b""
+ b't\xe3g')
+ self.assertEqual(ET.tostring(e, 'ascii'),
+ b"\n"
+ b'tãg')
- >>> e = ET.Element("{default}elem")
- >>> s = ET.SubElement(e, "{default}elem")
- >>> s = ET.SubElement(e, "{not-default}elem")
- >>> serialize(e, default_namespace="default") # 2
- ''
+ def test_issue3151(self):
+ e = ET.XML('')
+ self.assertEqual(e.tag, '{${stuff}}localname')
+ t = ET.ElementTree(e)
+ self.assertEqual(ET.tostring(e), b'')
- >>> e = ET.Element("{default}elem")
- >>> s = ET.SubElement(e, "{default}elem")
- >>> s = ET.SubElement(e, "elem") # unprefixed name
- >>> serialize(e, default_namespace="default") # 3
- Traceback (most recent call last):
- ValueError: cannot use non-qualified names with default_namespace option
+ def test_issue6565(self):
+ elem = ET.XML("")
+ self.assertEqual(summarize_list(elem), ['tag'])
+ newelem = ET.XML(SAMPLE_XML)
+ elem[:] = newelem[:]
+ self.assertEqual(summarize_list(elem), ['tag', 'tag', 'section'])
- """
+ def test_issue10777(self):
+ # Registering a namespace twice caused a "dictionary changed size during
+ # iteration" bug.
-def bug_200709_register_namespace():
- """
-
- >>> ET.tostring(ET.Element("{http://namespace.invalid/does/not/exist/}title"))
- b''
- >>> ET.register_namespace("foo", "http://namespace.invalid/does/not/exist/")
- >>> ET.tostring(ET.Element("{http://namespace.invalid/does/not/exist/}title"))
- b''
-
- And the Dublin Core namespace is in the default list:
-
- >>> ET.tostring(ET.Element("{http://purl.org/dc/elements/1.1/}title"))
- b''
-
- """
-
-def bug_200709_element_comment():
- """
-
- Not sure if this can be fixed, really (since the serializer needs
- ET.Comment, not cET.comment).
-
- >>> a = ET.Element('a')
- >>> a.append(ET.Comment('foo'))
- >>> a[0].tag == ET.Comment
- True
-
- >>> a = ET.Element('a')
- >>> a.append(ET.PI('foo'))
- >>> a[0].tag == ET.PI
- True
-
- """
-
-def bug_200709_element_insert():
- """
-
- >>> a = ET.Element('a')
- >>> b = ET.SubElement(a, 'b')
- >>> c = ET.SubElement(a, 'c')
- >>> d = ET.Element('d')
- >>> a.insert(0, d)
- >>> summarize_list(a)
- ['d', 'b', 'c']
- >>> a.insert(-1, d)
- >>> summarize_list(a)
- ['d', 'b', 'd', 'c']
-
- """
-
-def bug_200709_iter_comment():
- """
-
- >>> a = ET.Element('a')
- >>> b = ET.SubElement(a, 'b')
- >>> comment_b = ET.Comment("TEST-b")
- >>> b.append(comment_b)
- >>> summarize_list(a.iter(ET.Comment))
- ['']
-
- """
-
-# --------------------------------------------------------------------
-# reported on bugs.python.org
-
-def bug_1534630():
- """
-
- >>> bob = ET.TreeBuilder()
- >>> e = bob.data("data")
- >>> e = bob.start("tag", {})
- >>> e = bob.end("tag")
- >>> e = bob.close()
- >>> serialize(e)
- ''
-
- """
-
-def check_issue6233():
- """
-
- >>> e = ET.XML(b"t\\xc3\\xa3g")
- >>> ET.tostring(e, 'ascii')
- b"\\ntãg"
- >>> e = ET.XML(b"t\\xe3g")
- >>> ET.tostring(e, 'ascii')
- b"\\ntãg"
-
- """
-
-def check_issue3151():
- """
-
- >>> e = ET.XML('')
- >>> e.tag
- '{${stuff}}localname'
- >>> t = ET.ElementTree(e)
- >>> ET.tostring(e)
- b''
-
- """
-
-def check_issue6565():
- """
-
- >>> elem = ET.XML("")
- >>> summarize_list(elem)
- ['tag']
- >>> newelem = ET.XML(SAMPLE_XML)
- >>> elem[:] = newelem[:]
- >>> summarize_list(elem)
- ['tag', 'tag', 'section']
-
- """
-
-def check_issue10777():
- """
- Registering a namespace twice caused a "dictionary changed size during
- iteration" bug.
-
- >>> ET.register_namespace('test10777', 'http://myuri/')
- >>> ET.register_namespace('test10777', 'http://myuri/')
- """
+ ET.register_namespace('test10777', 'http://myuri/')
+ ET.register_namespace('test10777', 'http://myuri/')
# --------------------------------------------------------------------
@@ -1698,7 +1493,7 @@ class BasicElementTest(ElementTestCase, unittest.TestCase):
self.assertEqual(len(e2), 2)
self.assertEqualElements(e, e2)
-class ElementTreeTest(unittest.TestCase):
+class ElementTreeTypeTest(unittest.TestCase):
def test_istype(self):
self.assertIsInstance(ET.ParseError, type)
self.assertIsInstance(ET.QName, type)
@@ -1738,19 +1533,6 @@ class ElementTreeTest(unittest.TestCase):
mye = MyElement('joe')
self.assertEqual(mye.newmethod(), 'joe')
- def test_html_empty_elems_serialization(self):
- # issue 15970
- # from http://www.w3.org/TR/html401/index/elements.html
- for element in ['AREA', 'BASE', 'BASEFONT', 'BR', 'COL', 'FRAME', 'HR',
- 'IMG', 'INPUT', 'ISINDEX', 'LINK', 'META', 'PARAM']:
- for elem in [element, element.lower()]:
- expected = '<%s>' % elem
- serialized = serialize(ET.XML('<%s />' % elem), method='html')
- self.assertEqual(serialized, expected)
- serialized = serialize(ET.XML('<%s>%s>' % (elem,elem)),
- method='html')
- self.assertEqual(serialized, expected)
-
class ElementFindTest(unittest.TestCase):
def test_find_simple(self):
@@ -2064,31 +1846,6 @@ class TreeBuilderTest(unittest.TestCase):
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'))
-class XincludeTest(unittest.TestCase):
- def _my_loader(self, href, parse):
- # Used to avoid a test-dependency problem where the default loader
- # of ElementInclude uses the pyET parser for cET tests.
- if parse == 'xml':
- with open(href, 'rb') as f:
- return ET.parse(f).getroot()
- else:
- return None
-
- def test_xinclude_default(self):
- from xml.etree import ElementInclude
- doc = xinclude_loader('default.xml')
- ElementInclude.include(doc, self._my_loader)
- s = serialize(doc)
- self.assertEqual(s.strip(), '''
- Example.
-
- text
- texttail
-
-
-''')
-
-
class XMLParserTest(unittest.TestCase):
sample1 = '22'
sample2 = ('