changeset 27:4dc29d2eac0e

Force QName to be unicode. * emeraldtree/ElementTree.py: Convert all input for QName to unicode. * emeraldtree/tests/test_ElementTree.py: Check if members of QName are unicode.
author Bastian Blank <bblank@thinkmo.de>
date Thu, 12 Jun 2008 20:57:22 +0200
parents eeb0eb69c1da
children 21cef3864c33
files emeraldtree/ElementTree.py emeraldtree/tests/test_ElementTree.py
diffstat 2 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/emeraldtree/ElementTree.py	Sun Jun 08 12:40:21 2008 +0200
+++ b/emeraldtree/ElementTree.py	Thu Jun 12 20:57:22 2008 +0200
@@ -476,6 +476,7 @@
 
 class QName(object):
     def __init__(self, text, uri=None):
+        text = unicode(text)
         if text[0] == '{':
             if uri is not None:
                 raise ValueError
--- a/emeraldtree/tests/test_ElementTree.py	Sun Jun 08 12:40:21 2008 +0200
+++ b/emeraldtree/tests/test_ElementTree.py	Thu Jun 12 20:57:22 2008 +0200
@@ -115,15 +115,17 @@
     elem = ProcessingInstruction('a', 'b')
     assert serialize(elem) == '<?a b?>'
 
-def test_QName():
+def test_QName___init__():
     qname = QName('a')
     assert qname.uri is None
     assert qname.name == 'a'
+    assert isinstance(qname.name, unicode)
     assert str(qname) == 'a'
     assert qname.text == 'a'
 
     qname = QName('{b}a')
     assert qname.uri == 'b'
+    assert isinstance(qname.uri, unicode)
     assert qname.name == 'a'
     assert str(qname) == '{b}a'
     assert qname.text == '{b}a'
@@ -137,6 +139,12 @@
     py.test.raises(ValueError, QName, '{ba')
     py.test.raises(ValueError, QName, '{b}a', 'c')
 
+def test_QName___cmp__():
+    qname1 = QName('a')
+    qname2 = QName('a')
+
+    assert cmp(qname1, qname2) == 0
+
 def test_XMLParser_simple1():
     elem = XML('<a />')
     assert elem.tag == 'a'