source: exist/branches/proglue_production_rev4605_xquery4884/python/elementtree-1.3a6-20070220-badc/unittests/test_parse.py @ 4886

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/exist/branches/proglue_production_rev4605_xquery4884/python/elementtree-1.3a6-20070220-badc/unittests/test_parse.py@4886
Revision 4886, 2.0 KB checked in by sdonegan, 11 years ago (diff)

Creating operational branch for ndgUtils as used on proglue

Line 
1# $Id: test_parse.py 3298 2007-09-13 14:38:02Z fredrik $
2
3from support import *
4
5def parsefile():
6    """
7    Test parsing from file.
8
9    >>> tree = ET.parse("samples/simple.xml")
10    >>> normalize_crlf(tree)
11    >>> tree.write(sys.stdout)
12    <root>
13       <element key="value">text</element>
14       <element>text</element>tail
15       <empty-element />
16    </root>
17    >>> tree = ET.parse("samples/simple-ns.xml")
18    >>> normalize_crlf(tree)
19    >>> tree.write(sys.stdout)
20    <ns0:root xmlns:ns0="namespace">
21       <ns0:element key="value">text</ns0:element>
22       <ns0:element>text</ns0:element>tail
23       <ns0:empty-element />
24    </ns0:root>
25    """
26
27
28def parseliteral():
29    r"""
30    >>> element = ET.XML("<html><body>text</body></html>")
31    >>> ET.ElementTree(element).write(sys.stdout)
32    <html><body>text</body></html>
33    >>> element = ET.fromstring("<html><body>text</body></html>")
34    >>> ET.ElementTree(element).write(sys.stdout)
35    <html><body>text</body></html>
36    >>> sequence = ["<html><body>", "text</bo", "dy></html>"]
37    >>> element = ET.fromstringlist(sequence)
38    >>> ET.ElementTree(element).write(sys.stdout)
39    <html><body>text</body></html>
40    >>> print ET.tostring(element)
41    <html><body>text</body></html>
42    >>> print "".join(ET.tostringlist(element))
43    <html><body>text</body></html>
44    >>> print ET.tostring(element, "ascii")
45    <?xml version='1.0' encoding='ascii'?>
46    <html><body>text</body></html>
47    >>> _, ids = ET.XMLID("<html><body>text</body></html>")
48    >>> len(ids)
49    0
50    >>> _, ids = ET.XMLID("<html><body id='body'>text</body></html>")
51    >>> len(ids)
52    1
53    >>> ids["body"].tag
54    'body'
55    """
56
57def error(xml):
58    """
59    Test error handling.
60
61    >>> error("foo").position
62    (1, 0)
63    >>> error("<tag>&foo;</tag>").position
64    (1, 5)
65    >>> error("foobar<").position
66    (1, 6)
67
68    """
69    try:
70        ET.XML(xml)
71    except ET.ParseError:
72        return sys.exc_value
Note: See TracBrowser for help on using the repository browser.