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

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

Issue 18304: ElementTree -- provide a way to ignore namespace in tags and seaches
Patch Set: Created 3 years, 1 month 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 | Lib/xml/etree/ElementTree.py » ('j') | 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 copy 8 import copy
9 import html 9 import html
10 import io 10 import io
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 # 3) unknown namespaces 861 # 3) unknown namespaces
862 elem = ET.XML(SAMPLE_XML_NS) 862 elem = ET.XML(SAMPLE_XML_NS)
863 self.serialize_check(elem, 863 self.serialize_check(elem,
864 '<ns0:body xmlns:ns0="http://effbot.org/ns">\n' 864 '<ns0:body xmlns:ns0="http://effbot.org/ns">\n'
865 ' <ns0:tag>text</ns0:tag>\n' 865 ' <ns0:tag>text</ns0:tag>\n'
866 ' <ns0:tag />\n' 866 ' <ns0:tag />\n'
867 ' <ns0:section>\n' 867 ' <ns0:section>\n'
868 ' <ns0:tag>subtext</ns0:tag>\n' 868 ' <ns0:tag>subtext</ns0:tag>\n'
869 ' </ns0:section>\n' 869 ' </ns0:section>\n'
870 '</ns0:body>') 870 '</ns0:body>')
871
872 def test_strip_namespaces(self):
873 elem = ET.XML(SAMPLE_XML_NS)
874 elem.set('nons', 'attribute 1 without ns')
875 elem.set('{http://effbot.org/ns}withns', 'attribute 2 with ns')
876 elem[-1].set('{http://effbot.org/ns}yesns', 'attribute 3 with ns')
877
878 self.assertEqual(elem.tag, '{http://effbot.org/ns}body')
879 self.assertEqual(elem[0].tag, '{http://effbot.org/ns}tag')
880 self.assertEqual(elem[-1].tag, '{http://effbot.org/ns}section')
881 self.assertEqual(elem[-1][0].tag, '{http://effbot.org/ns}tag')
882
883 self.assertEqual(elem.get('nons'), 'attribute 1 without ns')
884 self.assertEqual(elem.get('{http://effbot.org/ns}withns'), 'attribute 2 with ns')
885 self.assertEqual(elem[-1].get('{http://effbot.org/ns}yesns'), 'attribute 3 with ns')
886
887 ET.strip_namespaces(elem)
888 self.assertEqual(elem.tag, 'body')
889 self.assertEqual(elem[0].tag, 'tag')
890 self.assertEqual(elem[-1].tag, 'section')
891 self.assertEqual(elem[-1][0].tag, 'tag')
892
893 self.assertEqual(elem.get('nons'), 'attribute 1 without ns')
894 self.assertEqual(elem.get('withns'), 'attribute 2 with ns')
895 self.assertEqual(elem[-1].get('yesns'), 'attribute 3 with ns')
896 self.assertIsNone(elem.get('{http://effbot.org/ns}withns'))
897 self.assertIsNone(elem[-1].get('{http://effbot.org/ns}yesns'))
871 898
872 def test_qname(self): 899 def test_qname(self):
873 # Test QName handling. 900 # Test QName handling.
874 901
875 # 1) decorated tags 902 # 1) decorated tags
876 903
877 elem = ET.Element("{uri}tag") 904 elem = ET.Element("{uri}tag")
878 self.serialize_check(elem, '<ns0:tag xmlns:ns0="uri" />') # 1.1 905 self.serialize_check(elem, '<ns0:tag xmlns:ns0="uri" />') # 1.1
879 elem = ET.Element(ET.QName("{uri}tag")) 906 elem = ET.Element(ET.QName("{uri}tag"))
880 self.serialize_check(elem, '<ns0:tag xmlns:ns0="uri" />') # 1.2 907 self.serialize_check(elem, '<ns0:tag xmlns:ns0="uri" />') # 1.2
(...skipping 2066 matching lines...) Expand 10 before | Expand all | Expand 10 after
2947 # XXX the C module should give the same warnings as the Python module 2974 # XXX the C module should give the same warnings as the Python module
2948 with CleanContext(quiet=(pyET is not ET)): 2975 with CleanContext(quiet=(pyET is not ET)):
2949 support.run_unittest(*test_classes) 2976 support.run_unittest(*test_classes)
2950 finally: 2977 finally:
2951 # don't interfere with subsequent tests 2978 # don't interfere with subsequent tests
2952 ET = pyET = None 2979 ET = pyET = None
2953 2980
2954 2981
2955 if __name__ == '__main__': 2982 if __name__ == '__main__':
2956 test_main() 2983 test_main()
OLDNEW
« no previous file with comments | « no previous file | Lib/xml/etree/ElementTree.py » ('j') | no next file with comments »

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