source: exist/branches/proglue_production_rev4605_xquery4884/python/elementtree-1.3a6-20070310-badc/unittests/test_element.py @ 4896

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

Revised compound code - does not include actual egg

Line 
1# $Id: test_element.py 3298 2007-09-13 14:38:02Z fredrik $
2
3import elementtree.ElementTree as ET
4
5def check_string(string):
6    len(string)
7    for char in string:
8        if len(char) != 1:
9            print "expected one-character string, got %r" % char
10    new_string = string + ""
11    new_string = string + " "
12    string[:0]
13
14def check_string_or_none(value):
15    if value is None:
16        return
17    return check_string(value)
18
19def check_mapping(mapping):
20    len(mapping)
21    keys = mapping.keys()
22    items = mapping.items()
23    for key in keys:
24        item = mapping[key]
25    mapping["key"] = "value"
26    if mapping["key"] != "value":
27        print "expected value string, got %r" % mapping["key"]
28
29def check_element(element):
30    if not hasattr(element, "tag"):
31        print "no tag member"
32    if not hasattr(element, "attrib"):
33        print "no attrib member"
34    if not hasattr(element, "text"):
35        print "no text member"
36    if not hasattr(element, "tail"):
37        print "no tail member"
38    check_string(element.tag)
39    check_mapping(element.attrib)
40    check_string_or_none(element.text)
41    check_string_or_none(element.tail)
42    for elem in element:
43        check_element(elem)
44
45def interface():
46    """
47    Test basic element tree interface.
48
49    >>> element = ET.Element("tag")
50    >>> check_element(element)
51    >>> subelement = ET.SubElement(element, "tag")
52    >>> check_element(subelement)
53    >>> check_element(element[0])
54    >>> check_element(element[-1])
55    >>> check_element(element.find("tag"))
56    >>> check_element(list(element.findall("tag"))[0])
57    """
Note: See TracBrowser for help on using the repository browser.