Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(158594)

Side by Side Diff: Lib/test/test_xml_etree.py

Issue 20375: ElementTree: Document handling processing instructions
Patch Set: Created 5 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # IMPORTANT: the same tests are run from "test_xml_etree_c" in order 1 # IMPORTANT: the same tests are run from "test_xml_etree_c" in order
2 # to ensure consistency between the C implementation and the Python 2 # to ensure consistency between the C implementation and the Python
3 # implementation. 3 # implementation.
4 # 4 #
5 # For this purpose, the module-level "ET" symbol is temporarily 5 # For this purpose, the module-level "ET" symbol is temporarily
6 # monkey-patched when running the "test_xml_etree_c" test suite. 6 # monkey-patched when running the "test_xml_etree_c" test suite.
7 7
8 import html 8 import html
9 import io 9 import io
10 import operator 10 import operator
(...skipping 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after
1605 elem[:] = newelem[:] 1605 elem[:] = newelem[:]
1606 self.assertEqual(summarize_list(elem), ['tag', 'tag', 'section']) 1606 self.assertEqual(summarize_list(elem), ['tag', 'tag', 'section'])
1607 1607
1608 def test_issue10777(self): 1608 def test_issue10777(self):
1609 # Registering a namespace twice caused a "dictionary changed size during 1609 # Registering a namespace twice caused a "dictionary changed size during
1610 # iteration" bug. 1610 # iteration" bug.
1611 1611
1612 ET.register_namespace('test10777', 'http://myuri/') 1612 ET.register_namespace('test10777', 'http://myuri/')
1613 ET.register_namespace('test10777', 'http://myuri/') 1613 ET.register_namespace('test10777', 'http://myuri/')
1614 1614
1615 def test_pi_treatment(self):
1616 root = ET.Element('body', { 'text': 'some text'})
1617 root.append(ET.ProcessingInstruction('verb', 'extra data'))
1618 tree = ET.ElementTree(root)
1619 stream = io.BytesIO()
1620 tree.write(stream)
1615 1621
1622 # PIs are serialized to XML..
1623 self.assertTrue(b'<?verb extra data?>' in bytes(stream.getbuffer()))
1624
1625 # ..but skipped when parsing XML
1626 stream.seek(0)
1627 tree2 = ET.parse(stream)
1628 self.assertTrue(len(tree2.getroot().getchildren()) == 0)
Claudiu.Popa 2014/03/19 11:48:55 Why not self.assertEqual(len(tree..), 0)?
Nikratio 2014/03/20 03:44:23 Done.
1629
1630
1631 def test_comment_treatment(self):
1632 root = ET.Element('body', { 'text': 'some text'})
1633 root.append(ET.Comment('not to be rendered'))
1634 tree = ET.ElementTree(root)
1635 stream = io.BytesIO()
1636 tree.write(stream)
1637
1638 # PIs are serialized to XML..
1639 self.assertTrue(b'<!--not to be rendered-->' in bytes(stream.getbuffer() ))
Claudiu.Popa 2014/03/19 11:48:55 self.assertIn(b'..', bytes(..)) is clearer.
Nikratio 2014/03/20 03:44:23 Done.
1640
1641 # ..but skipped when parsing XML
1642 stream.seek(0)
1643 tree2 = ET.parse(stream)
1644 self.assertTrue(len(tree2.getroot().getchildren()) == 0)
Claudiu.Popa 2014/03/19 11:48:55 As above.
Nikratio 2014/03/20 03:44:23 Done.
1645
1616 # -------------------------------------------------------------------- 1646 # --------------------------------------------------------------------
1617 1647
1618 1648
1619 class BasicElementTest(ElementTestCase, unittest.TestCase): 1649 class BasicElementTest(ElementTestCase, unittest.TestCase):
1620 def test_augmentation_type_errors(self): 1650 def test_augmentation_type_errors(self):
1621 e = ET.Element('joe') 1651 e = ET.Element('joe')
1622 self.assertRaises(TypeError, e.append, 'b') 1652 self.assertRaises(TypeError, e.append, 'b')
1623 self.assertRaises(TypeError, e.extend, [ET.Element('bar'), 'foo']) 1653 self.assertRaises(TypeError, e.extend, [ET.Element('bar'), 'foo'])
1624 self.assertRaises(TypeError, e.insert, 0, 'foo') 1654 self.assertRaises(TypeError, e.insert, 0, 'foo')
1625 1655
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after
2578 # XXX the C module should give the same warnings as the Python module 2608 # XXX the C module should give the same warnings as the Python module
2579 with CleanContext(quiet=(pyET is not ET)): 2609 with CleanContext(quiet=(pyET is not ET)):
2580 support.run_unittest(*test_classes) 2610 support.run_unittest(*test_classes)
2581 finally: 2611 finally:
2582 # don't interfere with subsequent tests 2612 # don't interfere with subsequent tests
2583 ET = pyET = None 2613 ET = pyET = None
2584 2614
2585 2615
2586 if __name__ == '__main__': 2616 if __name__ == '__main__':
2587 test_main() 2617 test_main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+