diff emeraldtree/tests/test_ElementTree.py @ 15:60f59340b897

Remove argument ordering weirdness of QName. * emeraldtree/ElementTree.py: Redefine interface of QName. * emeraldtree/tests/test_ElementTree.py: Add testcases.
author Bastian Blank <bblank@thinkmo.de>
date Sat, 31 May 2008 17:46:46 +0200
parents fc4b72233da0
children 533331338691
line wrap: on
line diff
--- a/emeraldtree/tests/test_ElementTree.py	Sat May 31 16:34:35 2008 +0200
+++ b/emeraldtree/tests/test_ElementTree.py	Sat May 31 17:46:46 2008 +0200
@@ -1,3 +1,4 @@
+import py.test
 from emeraldtree.ElementTree import *
 
 def serialize(elem, **options):
@@ -7,7 +8,7 @@
     tree.write(file, **options)
     return file.getvalue()
 
-def test_Element___init__():
+def test_Element():
     elem = Element('a')
     assert serialize(elem) == '<a />'
     assert isinstance(elem, Node)
@@ -62,6 +63,28 @@
     elem = ProcessingInstruction('a', 'b')
     assert serialize(elem) == '<?a b?>'
 
+def test_QName():
+    qname = QName('a')
+    assert qname.uri is None
+    assert qname.name == 'a'
+    assert str(qname) == 'a'
+    assert qname.text == 'a'
+
+    qname = QName('{b}a')
+    assert qname.uri == 'b'
+    assert qname.name == 'a'
+    assert str(qname) == '{b}a'
+    assert qname.text == '{b}a'
+
+    qname = QName('a', 'b')
+    assert qname.uri == 'b'
+    assert qname.name == 'a'
+    assert str(qname) == '{b}a'
+    assert qname.text == '{b}a'
+
+    py.test.raises(ValueError, QName, '{ba')
+    py.test.raises(ValueError, QName, '{b}a', 'c')
+
 def test_XMLParser_simple1():
     elem = XML('<a />')
     assert elem.tag == 'a'