summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGordon P. Hemsley <me@gphemsley.org>2019-04-28 04:41:43 (GMT)
committerStefan Behnel <stefan_ml@behnel.de>2019-04-28 04:41:43 (GMT)
commit50fed0b64faa3053300008ef5607b570fe209de6 (patch)
tree910091aaff91cd9329e2aa85de5e9ea1ff8ae82b
parent21a9ba1992775b5a833da28bfa0a9f028d1b6761 (diff)
downloadcpython-50fed0b64faa3053300008ef5607b570fe209de6.zip
cpython-50fed0b64faa3053300008ef5607b570fe209de6.tar.gz
cpython-50fed0b64faa3053300008ef5607b570fe209de6.tar.bz2
bpo-32424: Improve test coverage for xml.etree.ElementTree (GH-12891)
* Fix typo in test_cyclic_gc subtest * Improve test coverage for xml.etree.ElementTree
-rw-r--r--Lib/test/test_xml_etree.py87
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS.d/next/Tests/2019-04-21-17-53-50.bpo-32424.Q4rBmn.rst2
-rw-r--r--Misc/NEWS.d/next/Tests/2019-04-21-17-55-18.bpo-32424.yDy49h.rst1
4 files changed, 89 insertions, 2 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index 14ce32a..e0d2cb7 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -9,6 +9,7 @@ import copy
import functools
import html
import io
+import itertools
import locale
import operator
import pickle
@@ -1929,6 +1930,88 @@ class BugsTest(unittest.TestCase):
class BasicElementTest(ElementTestCase, unittest.TestCase):
+
+ def test___init__(self):
+ tag = "foo"
+ attrib = { "zix": "wyp" }
+
+ element_foo = ET.Element(tag, attrib)
+
+ # traits of an element
+ self.assertIsInstance(element_foo, ET.Element)
+ self.assertIn("tag", dir(element_foo))
+ self.assertIn("attrib", dir(element_foo))
+ self.assertIn("text", dir(element_foo))
+ self.assertIn("tail", dir(element_foo))
+
+ # string attributes have expected values
+ self.assertEqual(element_foo.tag, tag)
+ self.assertIsNone(element_foo.text)
+ self.assertIsNone(element_foo.tail)
+
+ # attrib is a copy
+ self.assertIsNot(element_foo.attrib, attrib)
+ self.assertEqual(element_foo.attrib, attrib)
+
+ # attrib isn't linked
+ attrib["bar"] = "baz"
+ self.assertIsNot(element_foo.attrib, attrib)
+ self.assertNotEqual(element_foo.attrib, attrib)
+
+ def test___copy__(self):
+ element_foo = ET.Element("foo", { "zix": "wyp" })
+ element_foo.append(ET.Element("bar", { "baz": "qix" }))
+
+ element_foo2 = copy.copy(element_foo)
+
+ # elements are not the same
+ self.assertIsNot(element_foo2, element_foo)
+
+ # string attributes are equal
+ self.assertEqual(element_foo2.tag, element_foo.tag)
+ self.assertEqual(element_foo2.text, element_foo.text)
+ self.assertEqual(element_foo2.tail, element_foo.tail)
+
+ # number of children is the same
+ self.assertEqual(len(element_foo2), len(element_foo))
+
+ # children are the same
+ for (child1, child2) in itertools.zip_longest(element_foo, element_foo2):
+ self.assertIs(child1, child2)
+
+ # attrib is a copy
+ self.assertEqual(element_foo2.attrib, element_foo.attrib)
+
+ def test___deepcopy__(self):
+ element_foo = ET.Element("foo", { "zix": "wyp" })
+ element_foo.append(ET.Element("bar", { "baz": "qix" }))
+
+ element_foo2 = copy.deepcopy(element_foo)
+
+ # elements are not the same
+ self.assertIsNot(element_foo2, element_foo)
+
+ # string attributes are equal
+ self.assertEqual(element_foo2.tag, element_foo.tag)
+ self.assertEqual(element_foo2.text, element_foo.text)
+ self.assertEqual(element_foo2.tail, element_foo.tail)
+
+ # number of children is the same
+ self.assertEqual(len(element_foo2), len(element_foo))
+
+ # children are not the same
+ for (child1, child2) in itertools.zip_longest(element_foo, element_foo2):
+ self.assertIsNot(child1, child2)
+
+ # attrib is a copy
+ self.assertIsNot(element_foo2.attrib, element_foo.attrib)
+ self.assertEqual(element_foo2.attrib, element_foo.attrib)
+
+ # attrib isn't linked
+ element_foo.attrib["bar"] = "baz"
+ self.assertIsNot(element_foo2.attrib, element_foo.attrib)
+ self.assertNotEqual(element_foo2.attrib, element_foo.attrib)
+
def test_augmentation_type_errors(self):
e = ET.Element('joe')
self.assertRaises(TypeError, e.append, 'b')
@@ -1984,9 +2067,9 @@ class BasicElementTest(ElementTestCase, unittest.TestCase):
e1 = ET.Element('e1')
e2 = ET.Element('e2')
e3 = ET.Element('e3')
- e1.append(e2)
- e2.append(e2)
e3.append(e1)
+ e2.append(e3)
+ e1.append(e2)
wref = weakref.ref(e1)
del e1, e2, e3
gc_collect()
diff --git a/Misc/ACKS b/Misc/ACKS
index 393ea20..300e788 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -647,6 +647,7 @@ Christian Heimes
Thomas Heller
Malte Helmert
Lance Finn Helsten
+Gordon P. Hemsley
Jonathan Hendry
Nathan Henrie
Michael Henry
diff --git a/Misc/NEWS.d/next/Tests/2019-04-21-17-53-50.bpo-32424.Q4rBmn.rst b/Misc/NEWS.d/next/Tests/2019-04-21-17-53-50.bpo-32424.Q4rBmn.rst
new file mode 100644
index 0000000..f057d7e
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2019-04-21-17-53-50.bpo-32424.Q4rBmn.rst
@@ -0,0 +1,2 @@
+Fix typo in test_cyclic_gc() test for xml.etree.ElementTree. Patch by Gordon
+P. Hemsley.
diff --git a/Misc/NEWS.d/next/Tests/2019-04-21-17-55-18.bpo-32424.yDy49h.rst b/Misc/NEWS.d/next/Tests/2019-04-21-17-55-18.bpo-32424.yDy49h.rst
new file mode 100644
index 0000000..bb0839f
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2019-04-21-17-55-18.bpo-32424.yDy49h.rst
@@ -0,0 +1 @@
+Improve test coverage for xml.etree.ElementTree. Patch by Gordon P. Hemsley.