Package lxml :: Module doctestcompare
[hide private]
[frames] | no frames]

Module doctestcompare

source code

lxml-based doctest output comparison.

Note: normally, you should just import the lxml.usedoctest and lxml.html.usedoctest modules from within a doctest, instead of this one:

>>> import lxml.usedoctest # for XML output

>>> import lxml.html.usedoctest # for HTML output

To use this module directly, you must call lxmldoctest.install(), which will cause doctest to use this in all subsequent calls.

This changes the way output is checked and comparisons are made for XML or HTML-like content.

XML or HTML content is noticed because the example starts with < (it's HTML if it starts with <html). You can also use the PARSE_HTML and PARSE_XML flags to force parsing.

Some rough wildcard-like things are allowed. Whitespace is generally ignored (except in attributes). In text (attributes and text in the body) you can use ... as a wildcard. In an example it also matches any trailing tags in the element, though it does not match leading tags. You may create a tag <any> or include an any attribute in the tag. An any tag matches any tag, while the attribute matches any and all attributes.

When a match fails, the reformatted example and gotten text is displayed (indented), and a rough diff-like output is given. Anything marked with - is in the output but wasn't supposed to be, and similarly + means its in the example but wasn't in the output.

You can disable parsing on one line with # doctest:+NOPARSE_MARKUP

Classes [hide private]
  LXMLOutputChecker
  LHTMLOutputChecker
  _RestoreChecker
Functions [hide private]
 
strip(v) source code
 
norm_whitespace(v) source code
 
html_fromstring(html) source code
 
install(html=False)
Install doctestcompare for all future doctests.
source code
 
temp_install(html=False, del_module=None)
Use this inside a doctest to enable this checker for this doctest only.
source code
 
_find_doctest_frame() source code
Variables [hide private]
  _IS_PYTHON_3 = False
  PARSE_HTML = 1024
  PARSE_XML = 2048
  NOPARSE_MARKUP = 4096
  _html_parser = etree.HTMLParser(recover= False, remove_blank_t...
  _repr_re = re.compile(r'^<[^>]+ (at|object) ')
  _norm_whitespace_re = re.compile(r'[ \t\n][ \t\n]+')
  __test__ = {'basic': '\n >>> temp_install()\n >>> print ...
  __package__ = 'lxml'
Function Details [hide private]

install(html=False)

source code 

Install doctestcompare for all future doctests.

If html is true, then by default the HTML parser will be used; otherwise the XML parser is used.

temp_install(html=False, del_module=None)

source code 

Use this inside a doctest to enable this checker for this doctest only.

If html is true, then by default the HTML parser will be used; otherwise the XML parser is used.


Variables Details [hide private]

_html_parser

Value:
etree.HTMLParser(recover= False, remove_blank_text= True)

__test__

Value:
{'basic': '''
    >>> temp_install()
    >>> print """<xml a="1" b="2">stuff</xml>"""
    <xml b="2" a="1">...</xml>
    >>> print """<xml xmlns="http://example.com"><tag   attr="bar"   /\
></xml>"""
    <xml xmlns="...">
      <tag attr="..." />
...