]> granicus.if.org Git - python/commitdiff
#12820: add tests for the xml.dom.minicompat module. Patch by John Chandler and...
authorEzio Melotti <ezio.melotti@gmail.com>
Wed, 10 Apr 2013 16:30:11 +0000 (19:30 +0300)
committerEzio Melotti <ezio.melotti@gmail.com>
Wed, 10 Apr 2013 16:30:11 +0000 (19:30 +0300)
Lib/test/test_xml_dom_minicompat.py [new file with mode: 0644]
Lib/test/xmltests.py
Misc/ACKS
Misc/NEWS

diff --git a/Lib/test/test_xml_dom_minicompat.py b/Lib/test/test_xml_dom_minicompat.py
new file mode 100644 (file)
index 0000000..085e52a
--- /dev/null
@@ -0,0 +1,101 @@
+# Tests for xml.dom.minicompat
+
+import pickle
+import unittest
+
+import xml.dom
+from xml.dom.minicompat import *
+
+
+class EmptyNodeListTestCase(unittest.TestCase):
+    """Tests for the EmptyNodeList class."""
+
+    def test_emptynodelist_item(self):
+        # Test item access on an EmptyNodeList.
+        node_list = EmptyNodeList()
+
+        self.assertIsNone(node_list.item(0))
+        self.assertIsNone(node_list.item(-1)) # invalid item
+
+        with self.assertRaises(IndexError):
+            node_list[0]
+        with self.assertRaises(IndexError):
+            node_list[-1]
+
+    def test_emptynodelist_length(self):
+        node_list = EmptyNodeList()
+        # Reading
+        self.assertEqual(node_list.length, 0)
+        # Writing
+        with self.assertRaises(xml.dom.NoModificationAllowedErr):
+            node_list.length = 111
+
+    def test_emptynodelist___add__(self):
+        node_list = EmptyNodeList() + NodeList()
+        self.assertEqual(node_list, NodeList())
+
+    def test_emptynodelist___radd__(self):
+        node_list = [1,2] + EmptyNodeList()
+        self.assertEqual(node_list, [1,2])
+
+
+class NodeListTestCase(unittest.TestCase):
+    """Tests for the NodeList class."""
+
+    def test_nodelist_item(self):
+        # Test items access on a NodeList.
+        # First, use an empty NodeList.
+        node_list = NodeList()
+
+        self.assertIsNone(node_list.item(0))
+        self.assertIsNone(node_list.item(-1))
+
+        with self.assertRaises(IndexError):
+            node_list[0]
+        with self.assertRaises(IndexError):
+            node_list[-1]
+
+        # Now, use a NodeList with items.
+        node_list.append(111)
+        node_list.append(999)
+
+        self.assertEqual(node_list.item(0), 111)
+        self.assertIsNone(node_list.item(-1)) # invalid item
+
+        self.assertEqual(node_list[0], 111)
+        self.assertEqual(node_list[-1], 999)
+
+    def test_nodelist_length(self):
+        node_list = NodeList([1, 2])
+        # Reading
+        self.assertEqual(node_list.length, 2)
+        # Writing
+        with self.assertRaises(xml.dom.NoModificationAllowedErr):
+            node_list.length = 111
+
+    def test_nodelist___add__(self):
+        node_list = NodeList([3, 4]) + [1, 2]
+        self.assertEqual(node_list, NodeList([3, 4, 1, 2]))
+
+    def test_nodelist___radd__(self):
+        node_list = [1, 2] + NodeList([3, 4])
+        self.assertEqual(node_list, NodeList([1, 2, 3, 4]))
+
+    def test_nodelist_pickle_roundtrip(self):
+        # Test pickling and unpickling of a NodeList.
+
+        # Empty NodeList.
+        node_list = NodeList()
+        pickled = pickle.dumps(node_list)
+        unpickled = pickle.loads(pickled)
+        self.assertEqual(unpickled, node_list)
+
+        # Non-empty NodeList.
+        node_list.append(1)
+        node_list.append(2)
+        pickled = pickle.dumps(node_list)
+        unpickled = pickle.loads(pickled)
+        self.assertEqual(unpickled, node_list)
+
+if __name__ == '__main__':
+    unittest.main()
index 0bfcba181e825f806eec7759eaec15334d31c907..bf685a466d7f1f363f7a5c58a929cd05819576d2 100644 (file)
@@ -15,6 +15,7 @@ def runtest(name):
 runtest("test.test_minidom")
 runtest("test.test_pyexpat")
 runtest("test.test_sax")
+runtest("test.test_xml_dom_minicompat")
 runtest("test.test_xml_etree")
 runtest("test.test_xml_etree_c")
 runtest("test.test_xmlrpc")
index f5269061a56c778c3fb36d05c55c1d9b6dbd1933..4f253e3bac56177b2812809bfafc1e069bc5ea1f 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -236,6 +236,7 @@ Paul Colomiets
 Christophe Combelles
 Geremy Condra
 Denver Coneybeare
+Phil Connell
 Juan José Conti
 Matt Conway
 David M. Cooke
index 744c71518119d87021c9ae80384a599783b2bd07..826ad8586099d1589e37de184a8b3eb2a92c1814 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -63,6 +63,12 @@ IDLE
 
 - Issue #6649: Fixed missing exit status in IDLE. Patch by Guilherme Polo.
 
+Tests
+-----
+
+- Issue #12820: add tests for the xml.dom.minicompat module.
+  Patch by John Chandler and Phil Connell.
+
 Documentation
 -------------