diff emeraldtree/tests/test_tree.py @ 55:125ce968352d

Tests for tree - Use unicode, style cleanup
author Bastian Blank <bblank@thinkmo.de>
date Mon, 20 Jul 2009 12:04:01 +0200
parents 6d2aaba7ac4d
children c1feee84d5d8
line wrap: on
line diff
--- a/emeraldtree/tests/test_tree.py	Mon Jul 20 12:00:06 2009 +0200
+++ b/emeraldtree/tests/test_tree.py	Mon Jul 20 12:04:01 2009 +0200
@@ -8,72 +8,72 @@
     return file.getvalue()
 
 def test_Element():
-    elem = Element('a')
+    elem = Element(u'a')
 
     assert isinstance(elem, Node)
-    assert elem.tag == 'a'
+    assert elem.tag == u'a'
 
 def test_Element__len__():
-    elem = Element('a', children=['1', '2', '3', '4', '5'])
+    elem = Element(u'a', children=(u'1', u'2', u'3', u'4', u'5'))
 
     assert len(elem) == 5
 
 def test_Element__nonzero__():
-    elem = Element('a')
+    elem = Element(u'a')
 
     assert elem
     assert len(elem) == 0
 
 def test_Element___getitem__():
-    elem = Element('a', children = [Element('b'), Element('c')])
+    elem = Element(u'a', children=(Element(u'b'), Element(u'c')))
 
-    assert elem[0].tag == 'b'
-    assert elem[1].tag == 'c'
+    assert elem[0].tag == u'b'
+    assert elem[1].tag == u'c'
     assert len(elem[:1]) == 1
     assert len(elem[:2]) == 2
     assert len(elem[:3]) == 2
     assert len(elem[1:3]) == 1
     assert len(elem[2:3]) == 0
-    assert elem[:2][0].tag == 'b'
-    assert elem[:2][1].tag == 'c'
+    assert elem[:2][0].tag == u'b'
+    assert elem[:2][1].tag == u'c'
 
 def test_Element___setitem__():
-    elem = Element('a', children = [Element('b1'), Element('b2')])
-
-    elem[0] = Element('c')
-    assert elem[0].tag == 'c'
-    assert elem[1].tag == 'b2'
+    elem = Element(u'a', children=(Element(u'b1'), Element(u'b2')))
 
-    elem[1] = Element('d')
-    assert elem[0].tag == 'c'
-    assert elem[1].tag == 'd'
+    elem[0] = Element(u'c')
+    assert elem[0].tag == u'c'
+    assert elem[1].tag == u'b2'
 
-    elem[0:0] = [Element('e')]
-    assert elem[0].tag == 'e'
-    assert elem[1].tag == 'c'
-    assert elem[2].tag == 'd'
+    elem[1] = Element(u'd')
+    assert elem[0].tag == u'c'
+    assert elem[1].tag == u'd'
+
+    elem[0:0] = [Element(u'e')]
+    assert elem[0].tag == u'e'
+    assert elem[1].tag == u'c'
+    assert elem[2].tag == u'd'
 
 def test_Element___delitem__():
-    elem = Element('a', children = [Element('b1'), Element('b2')])
+    elem = Element(u'a', children=(Element(u'b1'), Element(u'b2')))
 
     del elem[0]
     assert len(elem) == 1
-    assert elem[0].tag == 'b2'
+    assert elem[0].tag == u'b2'
 
 def test_Element_append():
-    elem = Element('a')
-
-    elem.append(Element('b'))
-    assert len(elem) == 1
-    assert elem[0].tag == 'b'
+    elem = Element(u'a')
 
-    elem.append(Element('c'))
+    elem.append(Element(u'b'))
+    assert len(elem) == 1
+    assert elem[0].tag == u'b'
+
+    elem.append(Element(u'c'))
     assert len(elem) == 2
-    assert elem[1].tag == 'c'
+    assert elem[1].tag == u'c'
 
-    elem.append('d')
+    elem.append(u'd')
     assert len(elem) == 3
-    assert elem[2] == 'd'
+    assert elem[2] == u'd'
 
 def test_Element_extend():
     pass
@@ -85,51 +85,51 @@
     pass
 
 def test_Element_find():
-    child_1 = Element('b1')
-    child_2 = Element('b2')
-    elem = Element('a', children=[child_1, child_2])
+    child_1 = Element(u'b1')
+    child_2 = Element(u'b2')
+    elem = Element(u'a', children=(child_1, child_2))
 
-    result = elem.find('b1')
+    result = elem.find(u'b1')
     assert result is child_1
 
-    result = elem.find('b2')
+    result = elem.find(u'b2')
     assert result is child_2
 
-    child_1 = Element(QName('b1', 'url1'))
-    child_2 = Element(QName('{url2}b2'))
-    elem = Element('a', children=[child_1, child_2])
+    child_1 = Element(QName(u'b1', u'url1'))
+    child_2 = Element(QName(u'{url2}b2'))
+    elem = Element(u'a', children=(child_1, child_2))
 
-    result = elem.find('{url1}b1')
+    result = elem.find(u'{url1}b1')
     assert result is child_1
 
 def test_Element_findtext():
     pass
 
 def test_Element_findall():
-    child_1 = Element('b1')
-    child_2 = Element('b2')
+    child_1 = Element(u'b1')
+    child_2 = Element(u'b2')
     child_3 = u"text"
-    elem = Element('a', children=[child_1, child_2, child_3])
+    elem = Element(u'a', children=(child_1, child_2, child_3))
 
-    result = list(elem.findall('b1'))
+    result = list(elem.findall(u'b1'))
     assert len(result) == 1
     assert result[0] is child_1
 
-    result = list(elem.findall('b2'))
+    result = list(elem.findall(u'b2'))
     assert len(result) == 1
     assert result[0] is child_2
 
-    result = list(elem.findall('*'))
+    result = list(elem.findall(u'*'))
     assert len(result) == 3
     assert result[0] is child_1
     assert result[1] is child_2
     assert result[2] is child_3
 
-    child_1 = Element(QName('b1', 'url1'))
-    child_2 = Element(QName('{url2}b2'))
-    elem = Element('a', children=[child_1, child_2])
+    child_1 = Element(QName(u'b1', u'url1'))
+    child_2 = Element(QName(u'{url2}b2'))
+    elem = Element(u'a', children=(child_1, child_2))
 
-    result = list(elem.findall('{url1}b1'))
+    result = list(elem.findall(u'{url1}b1'))
     assert len(result) == 1
     assert result[0] is child_1
 
@@ -149,125 +149,125 @@
     pass
 
 def test_Element_iter():
-    elem = Element('a')
+    elem = Element(u'a')
     l = list(elem.iter())
     assert len(l) == 1
 
-    elem.append('b')
+    elem.append(u'b')
     l = list(elem.iter())
     assert len(l) == 2
 
-    elem.append(Element('c'))
+    elem.append(Element(u'c'))
     l = list(elem.iter())
     assert len(l) == 3
 
-    elem.append('d')
+    elem.append(u'd')
     l = list(elem.iter())
     assert len(l) == 4
 
 def test_Element_itertext():
-    elem = Element('a')
+    elem = Element(u'a')
     l = list(elem.itertext())
     assert len(l) == 0
 
-    elem.append('b')
+    elem.append(u'b')
     l = list(elem.itertext())
     assert len(l) == 1
 
 def test_Comment():
-    elem = Comment('a')
-    assert serialize(elem) == '<!--a-->'
+    elem = Comment(u'a')
+    assert serialize(elem) == u'<!--a-->'
     assert isinstance(elem, Node)
 
 def test_ProcessingInstruction():
-    elem = ProcessingInstruction('a')
-    assert serialize(elem) == '<?a?>'
+    elem = ProcessingInstruction(u'a')
+    assert serialize(elem) == u'<?a?>'
     assert isinstance(elem, ProcessingInstruction)
 
-    elem = ProcessingInstruction('a', 'b')
-    assert serialize(elem) == '<?a b?>'
+    elem = ProcessingInstruction(u'a', u'b')
+    assert serialize(elem) == u'<?a b?>'
 
 def test_QName___init__():
-    qname = QName('a')
+    qname = QName(u'a')
     assert qname.uri is None
-    assert qname.name == 'a'
+    assert qname.name == u'a'
     assert isinstance(qname.name, unicode)
-    assert str(qname) == 'a'
-    assert qname.text == 'a'
+    assert str(qname) == u'a'
+    assert qname.text == u'a'
 
-    qname = QName('{b}a')
-    assert qname.uri == 'b'
+    qname = QName(u'{b}a')
+    assert qname.uri == u'b'
     assert isinstance(qname.uri, unicode)
-    assert qname.name == 'a'
-    assert str(qname) == '{b}a'
-    assert qname.text == '{b}a'
+    assert qname.name == u'a'
+    assert str(qname) == u'{b}a'
+    assert qname.text == u'{b}a'
 
-    qname = QName('a', 'b')
-    assert qname.uri == 'b'
-    assert qname.name == 'a'
-    assert str(qname) == '{b}a'
-    assert qname.text == '{b}a'
+    qname = QName(u'a', u'b')
+    assert qname.uri == u'b'
+    assert qname.name == u'a'
+    assert str(qname) == u'{b}a'
+    assert qname.text == u'{b}a'
 
-    py.test.raises(ValueError, QName, '{ba')
-    py.test.raises(ValueError, QName, '{b}a', 'c')
+    py.test.raises(ValueError, QName, u'{bau')
+    py.test.raises(ValueError, QName, u'{b}a', u'c')
 
 def test_QName___cmp__():
-    qname1 = QName('a')
-    qname2 = QName('a')
+    qname1 = QName(u'a')
+    qname2 = QName(u'a')
 
     assert qname1 == qname2
-    assert qname1 == 'a'
-    assert 'a' == qname1
+    assert qname1 == u'a'
+    assert u'a' == qname1
 
-    qname1 = QName('a', 'b')
-    qname2 = QName('{b}a')
+    qname1 = QName(u'a', u'b')
+    qname2 = QName(u'{b}a')
 
     assert qname1 == qname2
-    assert qname1 == '{b}a'
-    assert '{b}a' == qname1
+    assert qname1 == u'{b}a'
+    assert u'{b}a' == qname1
 
 def test_XMLParser_simple1():
-    elem = XML('<a />')
-    assert elem.tag == 'a'
+    elem = XML(u'<a />')
+    assert elem.tag == u'a'
     assert len(elem) == 0
 
 def test_XMLParser_simple2():
-    elem = XML('<a><b /></a>')
-    assert elem.tag == 'a'
+    elem = XML(u'<a><b /></a>')
+    assert elem.tag == u'a'
     assert len(elem) == 1
-    assert elem[0].tag == 'b'
+    assert elem[0].tag == u'b'
     assert len(elem[0]) == 0
 
 def test_XMLParser_text1():
-    elem = XML('<a>b</a>')
-    assert elem.tag == 'a'
+    elem = XML(u'<a>b</a>')
+    assert elem.tag == u'a'
     assert isinstance(elem, Element)
     assert len(elem) == 1
-    assert elem[0] == 'b'
+    assert elem[0] == u'b'
     assert isinstance(elem[0], unicode)
 
 def test_XMLParser_text2():
-    elem = XML('<a>b<c>d</c>d</a>')
-    assert elem.tag == 'a'
+    elem = XML(u'<a>b<c>d</c>d</a>')
+    assert elem.tag == u'a'
     assert len(elem) == 3
-    assert elem[0] == 'b'
-    assert elem[1].tag == 'c'
-    assert elem[2] == 'd'
+    assert elem[0] == u'b'
+    assert elem[1].tag == u'c'
+    assert elem[2] == u'd'
 
 def test_XMLParser_namespace_1():
-    elem = XML('<b xmlns="c" d="e"/>')
+    elem = XML(u'<b xmlns="c" d="e"/>')
     assert isinstance(elem.tag, QName)
-    assert elem.tag == QName('b', 'c')
-    assert elem.attrib == {QName('d', None): 'e'}
-    assert serialize(elem) == '<ns0:b d="e" xmlns:ns0="c" />'
-    assert serialize(elem, namespaces={'c': ''}) == '<b d="e" xmlns="c" />'
+    assert elem.tag == QName(u'b', u'c')
+    assert elem.attrib == {QName(u'd', None): u'e'}
+    assert serialize(elem) == u'<ns0:b d="e" xmlns:ns0="c" />'
+    assert serialize(elem, namespaces={u'c': u''}) == u'<b d="e" xmlns="c" />'
 
 def test_XMLParser_namespace_2():
-    elem = XML('<a:b xmlns:a="c" d="e" a:f="g"/>')
+    elem = XML(u'<a:b xmlns:a="c" d="e" a:f="g"/>')
     assert isinstance(elem.tag, QName)
-    assert elem.tag == QName('b', 'c')
-    assert elem.attrib == {'d': 'e', QName('f', 'c'): 'g'}
-    assert serialize(elem) == '<ns0:b d="e" ns0:f="g" xmlns:ns0="c" />'
-    assert serialize(elem, namespaces={'c': ''}) == '<b d="e" f="g" xmlns="c" />'
+    assert elem.tag == QName(u'b', u'c')
+    assert elem.attrib == {u'd': u'e', QName(u'f', u'c'): u'g'}
+    assert serialize(elem) == u'<ns0:b d="e" ns0:f="g" xmlns:ns0="c" />'
+    assert serialize(elem, namespaces={u'c': u''}) == u'<b d="e" f="g" xmlns="c" />'