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

Unified Diff: Lib/test/test_xml_etree.py

Issue 18304: ElementTree -- provide a way to ignore namespace in tags and seaches
Patch Set: Created 2 years, 11 months ago
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Lib/xml/etree/ElementTree.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/test/test_xml_etree.py Wed Jul 27 16:59:22 2016 +0200
+++ b/Lib/test/test_xml_etree.py Wed Jul 27 19:56:56 2016 +0200
@@ -869,6 +869,33 @@
' </ns0:section>\n'
'</ns0:body>')
+ def test_strip_namespaces(self):
+ elem = ET.XML(SAMPLE_XML_NS)
+ elem.set('nons', 'attribute 1 without ns')
+ elem.set('{http://effbot.org/ns}withns', 'attribute 2 with ns')
+ elem[-1].set('{http://effbot.org/ns}yesns', 'attribute 3 with ns')
+
+ self.assertEqual(elem.tag, '{http://effbot.org/ns}body')
+ self.assertEqual(elem[0].tag, '{http://effbot.org/ns}tag')
+ self.assertEqual(elem[-1].tag, '{http://effbot.org/ns}section')
+ self.assertEqual(elem[-1][0].tag, '{http://effbot.org/ns}tag')
+
+ self.assertEqual(elem.get('nons'), 'attribute 1 without ns')
+ self.assertEqual(elem.get('{http://effbot.org/ns}withns'), 'attribute 2 with ns')
+ self.assertEqual(elem[-1].get('{http://effbot.org/ns}yesns'), 'attribute 3 with ns')
+
+ ET.strip_namespaces(elem)
+ self.assertEqual(elem.tag, 'body')
+ self.assertEqual(elem[0].tag, 'tag')
+ self.assertEqual(elem[-1].tag, 'section')
+ self.assertEqual(elem[-1][0].tag, 'tag')
+
+ self.assertEqual(elem.get('nons'), 'attribute 1 without ns')
+ self.assertEqual(elem.get('withns'), 'attribute 2 with ns')
+ self.assertEqual(elem[-1].get('yesns'), 'attribute 3 with ns')
+ self.assertIsNone(elem.get('{http://effbot.org/ns}withns'))
+ self.assertIsNone(elem[-1].get('{http://effbot.org/ns}yesns'))
+
def test_qname(self):
# Test QName handling.
« 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+