summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_minidom.py
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2011-11-18 15:36:07 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2011-11-18 15:36:07 (GMT)
commitdef4728fd65535c0502fc7e8297d99aead7568a2 (patch)
tree624494840efeaa92d4d850cb10e5a1dfdc1e13cd /Lib/test/test_minidom.py
parent4d5d4e28557d2afb00d04b649fb58c62b7e51995 (diff)
parent8008f2aba0c063a882c33ebd4b39a5a560deb8c0 (diff)
downloadcpython-def4728fd65535c0502fc7e8297d99aead7568a2.zip
cpython-def4728fd65535c0502fc7e8297d99aead7568a2.tar.gz
cpython-def4728fd65535c0502fc7e8297d99aead7568a2.tar.bz2
#4147: merge with 3.2.
Diffstat (limited to 'Lib/test/test_minidom.py')
-rw-r--r--Lib/test/test_minidom.py37
1 files changed, 32 insertions, 5 deletions
diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py
index 2621f72..392e40e 100644
--- a/Lib/test/test_minidom.py
+++ b/Lib/test/test_minidom.py
@@ -467,12 +467,39 @@ class MinidomTest(unittest.TestCase):
dom.unlink()
self.confirm(domstr == str.replace("\n", "\r\n"))
+ def test_toprettyxml_with_text_nodes(self):
+ # see issue #4147, text nodes are not indented
+ decl = '<?xml version="1.0" ?>\n'
+ self.assertEqual(parseString('<B>A</B>').toprettyxml(),
+ decl + '<B>A</B>\n')
+ self.assertEqual(parseString('<C>A<B>A</B></C>').toprettyxml(),
+ decl + '<C>\n\tA\n\t<B>A</B>\n</C>\n')
+ self.assertEqual(parseString('<C><B>A</B>A</C>').toprettyxml(),
+ decl + '<C>\n\t<B>A</B>\n\tA\n</C>\n')
+ self.assertEqual(parseString('<C><B>A</B><B>A</B></C>').toprettyxml(),
+ decl + '<C>\n\t<B>A</B>\n\t<B>A</B>\n</C>\n')
+ self.assertEqual(parseString('<C><B>A</B>A<B>A</B></C>').toprettyxml(),
+ decl + '<C>\n\t<B>A</B>\n\tA\n\t<B>A</B>\n</C>\n')
+
+ def test_toprettyxml_with_adjacent_text_nodes(self):
+ # see issue #4147, adjacent text nodes are indented normally
+ dom = Document()
+ elem = dom.createElement('elem')
+ elem.appendChild(dom.createTextNode('TEXT'))
+ elem.appendChild(dom.createTextNode('TEXT'))
+ dom.appendChild(elem)
+ decl = '<?xml version="1.0" ?>\n'
+ self.assertEqual(dom.toprettyxml(),
+ decl + '<elem>\n\tTEXT\n\tTEXT\n</elem>\n')
+
def test_toprettyxml_preserves_content_of_text_node(self):
- str = '<A>B</A>'
- dom = parseString(str)
- dom2 = parseString(dom.toprettyxml())
- self.assertEqual(dom.childNodes[0].childNodes[0].toxml(),
- dom2.childNodes[0].childNodes[0].toxml())
+ # see issue #4147
+ for str in ('<B>A</B>', '<A><B>C</B></A>'):
+ dom = parseString(str)
+ dom2 = parseString(dom.toprettyxml())
+ self.assertEqual(
+ dom.getElementsByTagName('B')[0].childNodes[0].toxml(),
+ dom2.getElementsByTagName('B')[0].childNodes[0].toxml())
def testProcessingInstruction(self):
dom = parseString('<e><?mypi \t\n data \t\n ?></e>')