[Lxml-checkins] r46502 - lxml/trunk/src/lxml/tests

scoder at codespeak.net scoder at codespeak.net
Wed Sep 12 15:09:06 CEST 2007


Author: scoder
Date: Wed Sep 12 15:09:06 2007
New Revision: 46502

Modified:
   lxml/trunk/src/lxml/tests/test_elementtree.py
Log:
test cases for serialising namespace declarations

Modified: lxml/trunk/src/lxml/tests/test_elementtree.py
==============================================================================
--- lxml/trunk/src/lxml/tests/test_elementtree.py	(original)
+++ lxml/trunk/src/lxml/tests/test_elementtree.py	Wed Sep 12 15:09:06 2007
@@ -1986,6 +1986,37 @@
         del one
         self.assertEquals('{http://a.b.c}baz', baz.tag)
 
+    def test_ns_decl(self):
+        tostring = self.etree.tostring
+        root = self.etree.XML(
+            '<foo><bar xmlns:ns="http://a.b.c"><ns:baz/></bar></foo>')
+        baz = root[0][0]
+
+        nsdecl = re.findall("xmlns(?::[a-z0-9]+)?=[\"']([^\"']+)[\"']",
+                            tostring(baz))
+        self.assertEquals(["http://a.b.c"], nsdecl)
+
+    def test_ns_decl_default(self):
+        tostring = self.etree.tostring
+        root = self.etree.XML(
+            '<foo><bar xmlns="http://a.b.c"><baz/></bar></foo>')
+        baz = root[0][0]
+
+        nsdecl = re.findall("xmlns(?::[a-z0-9]+)?=[\"']([^\"']+)[\"']",
+                            tostring(baz))
+        self.assertEquals(["http://a.b.c"], nsdecl)
+        
+    def test_ns_decl_root(self):
+        tostring = self.etree.tostring
+        root = self.etree.XML(
+            '<foo xmlns:ns="http://a.b.c"><bar><ns:baz/></bar></foo>')
+        baz = root[0][0]
+
+        nsdecl = re.findall("xmlns(?::[a-z0-9]+)?=[\"']([^\"']+)[\"']",
+                            tostring(baz))
+
+        self.assertEquals(["http://a.b.c"], nsdecl)
+
     def test_attribute_xmlns_move(self):
         Element = self.etree.Element
 


More information about the lxml-checkins mailing list