File: test_nodeiterator.py

package info (click to toggle)
qm 1.1.3-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 8,628 kB
  • ctags: 10,249
  • sloc: python: 41,482; ansic: 20,611; xml: 12,837; sh: 485; makefile: 226
file content (75 lines) | stat: -rw-r--r-- 1,855 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def test(tester):

    tester.startGroup('NodeIterator')


    tester.startTest('Checking syntax')
    try:
        from xml.dom import NodeIterator
        from xml.dom.NodeIterator import NodeIterator
    except:
        tester.error('Error in syntax', 1)
    tester.testDone()

    tester.startTest('Creating test environment')
    from xml.dom import implementation
    doc = implementation.createDocument('',None,None);

    #xml_string = '<a><b><c/><d/></b><e><f/><g/></e></a>'
    try:
        a = doc.createElement('a')
        b = doc.createElement('b')
        c = doc.createElement('c')
        d = doc.createElement('d')
        e = doc.createElement('e')
        f = doc.createElement('f')
        g = doc.createElement('g')
    except:
        tester.error('Couldn\'t create elements')
    try:
        b.appendChild(c)
        b.appendChild(d)
        a.appendChild(b)
        e.appendChild(f)
        e.appendChild(g)
        a.appendChild(e)
        doc.appendChild(a)
    except:
        tester.error('Counl\'t append to DOM tree')

    from xml.dom.NodeFilter import NodeFilter
    nit = doc.createNodeIterator(doc, NodeFilter.SHOW_ELEMENT, None,1)
    tester.testDone()


    tester.startTest('Iterating forward')
    curr_node =  nit.nextNode()
    while curr_node:
        curr_node =  nit.nextNode()
    tester.testDone()


    tester.startTest('Iterating in reverse')
    curr_node =  nit.previousNode()   
    while curr_node:
        curr_node =  nit.previousNode()
    tester.testDone()


    tester.startTest('Iterating forward again')
    curr_node =  nit.nextNode()
    while curr_node:
        curr_node =  nit.nextNode()
    tester.testDone()


    return tester.groupDone()


if __name__ == '__main__':
    import sys
    import TestSuite

    tester = TestSuite.TestSuite()
    retVal = test(tester)
    sys.exit(retVal)