Home | Trees | Indices | Help |
|
---|
|
1 import sys 2 import unittest 3 4 from lxml import etree 5 from lxml.tests.common_imports import HelperTestCase 6 from lxml.doctestcompare import LXMLOutputChecker, PARSE_HTML, PARSE_XML 7 8 13 1416 i = "\n" + level*" " 17 if len(elem): 18 if not elem.text or not elem.text.strip(): 19 elem.text = i + " " 20 if not elem.tail or not elem.tail.strip(): 21 elem.tail = i 22 for elem in elem: 23 indent(elem, level+1) 24 if not elem.tail or not elem.tail.strip(): 25 elem.tail = i 26 else: 27 if level and (not elem.tail or not elem.tail.strip()): 28 elem.tail = i29 3032 _checker = LXMLOutputChecker() 3385 8635 if html: 36 options = PARSE_HTML 37 else: 38 options = PARSE_XML 39 40 parse = self._checker.get_parser(want, got, options) 41 want_doc = parse(want) 42 got_doc = parse(got) 43 return self._checker.collect_diff( 44 want_doc, got_doc, html, indent=0).lstrip()45 4850 root = etree.fromstring(want) 51 root.tail = '\n' 52 indent(root) 53 diff = etree.tostring( 54 root, encoding='unicode', method=html and 'html' or 'xml') 55 self.assert_diff(want, got, diff, html=html)5658 self.assert_nodiff( 59 '<p title="expected">Expected</p>', 60 '<p title="expected">Expected</p>')61 67 73 7981 self.assert_diff( 82 '<p title="expected">Expected</p>', 83 '<p title="actual">Actual</p>', 84 '<p title="expected (got: actual)">Expected (got: Actual)</p>\n')88 suite = unittest.TestSuite() 89 if sys.version_info >= (2,4): 90 suite.addTests([unittest.makeSuite(DoctestCompareTest)]) 91 return suite92 93 94 if __name__ == '__main__': 95 unittest.main() 96
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Thu Aug 28 16:33:29 2014 | http://epydoc.sourceforge.net |