File: test_text.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 (66 lines) | stat: -rw-r--r-- 1,705 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
from xml.dom import DOMException
from xml.dom import INDEX_SIZE_ERR

def get_exception_name(code):
    import types
    from xml import dom
    for (name,value) in vars(dom).items():
        if (type(value) == types.IntType 
        and value == code):
            return name

def test(tester):

    tester.startGroup('Text')

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


    tester.startTest('Creating test environment')
    from xml.dom import implementation
    dt = implementation.createDocumentType('','','')
    doc = implementation.createDocument('','ROOT',dt)

    t = doc.createTextNode("ONETWO")
    tester.testDone()


    tester.startTest('Testing splitText()')
    t2 = t.splitText(3)
    if t.data != 'ONE':
        tester.error('splitText did not properly split first half')
    if t2.data != 'TWO':
        tester.error('splitText did not properly split second half')
    try:
        t.splitText(100)
    except DOMException, x:
        if x.code != INDEX_SIZE_ERR:
            name = get_exception_name(x.code)
            tester.error("Wrong exception '%s', expected INDEX_SIZE_ERR" % name)
    else:
        tester.error('splitText doesn\'t catch an invalid index')
    tester.testDone()


    tester.startTest('Testing cloneNode()')
    t3 = t.cloneNode(0)
    if t3.data != t.data:
        error("cloneNode does not copy data")
    tester.testDone()

    return tester.groupDone()


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

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