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

# Module test_xpathevaluator

source code

Test cases related to XPath evaluation and the XPath class

Classes | [hide private]
| ETreeXPathTestCase XPath tests etree
| ETreeXPathClassTestCase Tests for the XPath class
| ETreeETXPathClassTestCase Tests for the ETXPath class

Functions | [hide private]
tag(elem) | source code
stringTest(ctxt, s1) | source code
floatTest(ctxt, f1) | source code
booleanTest(ctxt, b1) | source code
setTest(ctxt, st1) | source code
setTest2(ctxt, st1) | source code
argsTest1(ctxt, s, f, b, st) | source code
argsTest2(ctxt, st1, st2) | source code
resultTypesTest(ctxt) | source code
resultTypesTest2(ctxt) | source code
xpath() Test xpath extension functions. | source code
test_suite() | source code

Variables | [hide private]
| SAMPLE_XML = `etree.parse(StringIO(`...``
| uri = ``'``http://www.example.com/``'``
| extension = ``{``(`None`,` `'``argsTest1``'``)``:` <function argsTest1 at 0x8f9`...``

Function Details | [hide private]

### xpath() | source code
Test xpath extension functions.
    >>> root = SAMPLE_XML
    >>> e = etree.XPathEvaluator(root, extensions=[extension])
    >>> e.evaluate("stringTest('you')")
    'Hello you'
    >>> e.evaluate(u"stringTest('élan')")
    u'Hello \xe9lan'
    >>> e.evaluate("stringTest('you','there')")
    Traceback (most recent call last):
    ...
    TypeError: stringTest() takes exactly 2 arguments (3 given)
    >>> e.evaluate("floatTest(2)")
    6.0
    >>> e.evaluate("booleanTest(true())")
    False
    >>> map(tag, e.evaluate("setTest(/body/tag)"))
    ['tag']
    >>> map(tag, e.evaluate("setTest2(/body/*)"))
    ['tag', 'section']
    >>> e.evaluate("argsTest1('a',1.5,true(),/body/tag)")
    "a, 1.5, True, ['tag', 'tag', 'tag']"
    >>> map(tag, e.evaluate("argsTest2(/body/tag, /body/section)"))
    ['tag', 'section', 'tag', 'tag']
    >>> e.evaluate("resultTypesTest()")
    Traceback (most recent call last):
    ...
    XPathResultError: This is not a node: 'x'
    >>> try:
    ...     e.evaluate("resultTypesTest2()")
    ... except etree.XPathResultError:
    ...     print "Got error"
    Got error

Variables Details | [hide private]

  ### SAMPLE_XML Value:
      etree.parse(StringIO("""
      <body>
        <tag>text</tag>
        <section>
          <tag>subtext</tag>
        </section>
        <tag />
        <tag />
      ...

  ### extension Value:
      {(None, 'stringTest'): stringTest, (None, 'floatTest'): floatTest, (No
      ne, 'booleanTest'): booleanTest, (None, 'setTest'): setTest, (None, 's
      etTest2'): setTest2, (None, 'argsTest1'): argsTest1, (None, 'argsTest2
      '): argsTest2, (None, 'resultTypesTest'): resultTypesTest, (None, 'res
      ultTypesTest2'): resultTypesTest2,}