lxml.tests.selftest2
Package lxml :: Package tests :: Module selftest2
[hide private]
[frames] | no frames]

Module selftest2

source code

Functions [hide private]
 
stdout() source code
 
unserialize(text) source code
 
serialize(elem, encoding=None) source code
 
summarize(elem) source code
 
summarize_list(seq) source code
 
check_string(string) source code
 
check_mapping(mapping) source code
 
check_element(element) source code
 
check_element_tree(tree) source code
 
element()
Test element tree interface.
source code
 
parsefile()
Test parsing from file. Note that we're opening the files in here; by default, the 'parse' function opens the file in binary mode, and doctest doesn't filter out carriage returns.
source code
 
writefile() source code
 
encoding()
Test encoding issues.
source code
 
qname()
Test QName handling.
source code
 
cdata()
Test CDATA handling (etc).
source code
 
find()
Test find methods (including xpath syntax).
source code
 
copy()
Test copy handling (etc).
source code
 
attrib()
Test attribute handling.
source code
 
makeelement()
Test makeelement handling.
source code
Variables [hide private]
  SAMPLE_XML = unserialize(...
  SAMPLE_XML_NS = unserialize(...
  ENTITY_XML = '<!DOCTYPE points [\n<!ENTITY % user-entities SYS...
  __package__ = 'lxml.tests'
Function Details [hide private]

qname()

source code 

Test QName handling.

  1. decorated tags
>>> elem = ElementTree.Element("{uri}tag")
>>> serialize(elem) # 1.1
'<ns0:tag xmlns:ns0="uri"/>'

## 2) decorated attributes

## >>> elem.attrib["{uri}key"] = "value" ## >>> serialize(elem) # 2.1 ## '<ns0:tag ns0:key="value" xmlns:ns0="uri"/>'

copy()

source code 

Test copy handling (etc).

>>> import copy
>>> e1 = unserialize("<tag>hello<foo/></tag>")
>>> # e2 = copy.copy(e1)
>>> e3 = copy.deepcopy(e1)
>>> e1.find("foo").tag = "bar"
>>> serialize(e1).replace(' ', '')
'<tag>hello<bar/></tag>'

## >>> serialize(e2).replace(' ', '') ## '<tag>hello<bar/></tag>'

>>> serialize(e3).replace(' ', '')
'<tag>hello<foo/></tag>'

Variables Details [hide private]

SAMPLE_XML

Value:
unserialize("""
<body>
  <tag>text</tag>
  <tag />
  <section>
    <tag>subtext</tag>
  </section>
</body>
...

SAMPLE_XML_NS

Value:
unserialize("""
<body xmlns="http://effbot.org/ns">
  <tag>text</tag>
  <tag />
  <section>
    <tag>subtext</tag>
  </section>
</body>
...

ENTITY_XML

Value:
'''<!DOCTYPE points [
<!ENTITY % user-entities SYSTEM \'user-entities.xml\'>
%user-entities;
]>
<document>&entity;</document>
'''