File: test_readers.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 (81 lines) | stat: -rw-r--r-- 2,082 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
76
77
78
79
80
81
import cStringIO
from xml.dom import DOMException
from xml.dom.ext import Print
from xml.dom.ext.reader import PyExpat, Sax2


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


expected_1 = source_1 = """\
<?xml version="1.0" encoding='utf-8'?>
<memo id="mydoc" xmlns:mkt="http://our.industry.org/schema/product-info"
      xmlns="http://xml-typographers.org/typo-markup-standard/1.0">
  <category>Marketing Request</category>
  <!-- A test comment -->
  <title>Re: Widget 404 Request</title>
  <para>
    <?PI test pi?>
    We need 5 of
      <mkt:product code="00808">
        <mkt:name>Widget 404</mkt:name>
        <mkt:description><![CDATA[Gee-gaw &]]> doo-dad</mkt:description>
      </mkt:product>
    to send out to reviewers this week.
  </para>
</memo>"""


#expected_1 = """<xsltemplate match="email/headers[substring-after(subject,\'address\')]"/>"""

        
def Test(tester):

    tester.startGroup("Testing PyExpat")

    reader = PyExpat.Reader()
    
    tester.startTest('Basic test')
    doc = reader.fromString(source_1)
    stream = cStringIO.StringIO()
    Print(doc, stream=stream)
    result = stream.getvalue()
    print result
    #if result != expected_1:
    #    tester.error('Expected\n"""%s"""\ngot\n"""%s"""'%(repr(expected_1), repr(result)))

    reader.releaseNode(doc)
        
    tester.groupDone()


    tester.startGroup("Testing Sax2")

    reader = Sax2.Reader()
    
    tester.startTest('Basic test')
    doc = reader.fromString(source_1)
    stream = cStringIO.StringIO()
    Print(doc, stream=stream)
    result = stream.getvalue()
    print result
    #if result != expected_1:
    #    tester.error('Expected\n"""%s"""\ngot\n"""%s"""'%(repr(expected_1), repr(result)))

    reader.releaseNode(doc)
        
    return tester.groupDone()


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

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