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

Module lxml.tests.test_xpathevaluator

Test cases related to XPath evaluation and the XPath class
Classes
ETreeETXPathClassTestCase Tests for the ETXPath class
ETreeXPathClassTestCase Tests for the XPath class
ETreeXPathTestCase XPath tests etree

Function Summary
  argsTest1(ctxt, s, f, b, st)
  argsTest2(ctxt, st1, st2)
  booleanTest(ctxt, b1)
  floatTest(ctxt, f1)
  resultTypesTest(ctxt)
  resultTypesTest2(ctxt)
  setTest(ctxt, st1)
  setTest2(ctxt, st1)
  stringTest(ctxt, s1)
  tag(elem)
  test_suite()
  xpath()
Test xpath extension functions.

Function Details

xpath()

Test xpath extension functions.
>>> root = SAMPLE_XML
>>> e = etree.XPathEvaluator(root, None, [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

Generated by Epydoc 2.1 on Thu Jul 26 19:14:08 2007 http://epydoc.sf.net