本文整理匯總了Python中lxml.doctestcompare.LXMLOutputChecker.output_difference方法的典型用法代碼示例。如果您正苦於以下問題:Python LXMLOutputChecker.output_difference方法的具體用法?Python LXMLOutputChecker.output_difference怎麽用?Python LXMLOutputChecker.output_difference使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類lxml.doctestcompare.LXMLOutputChecker
的用法示例。
在下文中一共展示了LXMLOutputChecker.output_difference方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: assert_xml_equal
# 需要導入模塊: from lxml.doctestcompare import LXMLOutputChecker [as 別名]
# 或者: from lxml.doctestcompare.LXMLOutputChecker import output_difference [as 別名]
def assert_xml_equal(got, want):
got = lxml.html.tostring(got)
want = lxml.html.tostring(want)
checker = LXMLOutputChecker()
if not checker.check_output(want, got, 0):
message = checker.output_difference(Example("", want), got, 0)
raise AssertionError(message)
示例2: assertXmlEqual
# 需要導入模塊: from lxml.doctestcompare import LXMLOutputChecker [as 別名]
# 或者: from lxml.doctestcompare.LXMLOutputChecker import output_difference [as 別名]
def assertXmlEqual(result, expect):
from doctest import Example
from lxml.doctestcompare import LXMLOutputChecker
checker = LXMLOutputChecker()
if not checker.check_output(expect, result, 0):
message = checker.output_difference(Example("", expect), result, 0)
raise AssertionError(message)
示例3: assertXmlEqual
# 需要導入模塊: from lxml.doctestcompare import LXMLOutputChecker [as 別名]
# 或者: from lxml.doctestcompare.LXMLOutputChecker import output_difference [as 別名]
def assertXmlEqual(self, got, want):
""" fail if the two objects are not equal XML serializations
In case of a failure, both serializations are pretty printed
with differences marked.
There is not check well-formedness or against any schema, only
slightly intelligent matching of the tested string to the reference
string.
'...' can be used as a wildcard instead of nodes or attribute values.
Wildcard Examples:
<foo>...</foo>
<foo bar="..." />
Arguments:
got -- string to check, as unicode string
want -- reference string, as unicode string
Usage Example:
self.assertXmlEqual(etree.tounicode(...), reference)
"""
checker = LXMLOutputChecker()
if not checker.check_output(want, got, 0):
message = checker.output_difference(Example("", want), got, 0)
raise AssertionError(message)
示例4: assertXmlEqual
# 需要導入模塊: from lxml.doctestcompare import LXMLOutputChecker [as 別名]
# 或者: from lxml.doctestcompare.LXMLOutputChecker import output_difference [as 別名]
def assertXmlEqual(self, want, got):
checker = LXMLOutputChecker()
if not checker.check_output(want, got, 0):
message = checker.output_difference(Example("", want), got, 0)
for line in difflib.unified_diff(want.splitlines(1), got.splitlines(1), fromfile='want.xml', tofile='got.xml'):
print line
raise AssertionError(message)
示例5: assert_xml_equal
# 需要導入模塊: from lxml.doctestcompare import LXMLOutputChecker [as 別名]
# 或者: from lxml.doctestcompare.LXMLOutputChecker import output_difference [as 別名]
def assert_xml_equal(got, want):
assert want is not None, 'Wanted XML cannot be None'
if got is None:
raise AssertionError('Got input to validate was None')
checker = LXMLOutputChecker()
if not checker.check_output(want, got, 0):
message = checker.output_difference(Example("", want), got, 0)
raise AssertionError(message)
示例6: assertXmlEqual
# 需要導入模塊: from lxml.doctestcompare import LXMLOutputChecker [as 別名]
# 或者: from lxml.doctestcompare.LXMLOutputChecker import output_difference [as 別名]
def assertXmlEqual(self, got, want):
from lxml.doctestcompare import LXMLOutputChecker
from doctest import Example
checker = LXMLOutputChecker()
if checker.check_output(want, got, 0):
return
message = checker.output_difference(Example("", want), got, 0)
raise AssertionError(message)
示例7: assertXmlFilesEqual
# 需要導入模塊: from lxml.doctestcompare import LXMLOutputChecker [as 別名]
# 或者: from lxml.doctestcompare.LXMLOutputChecker import output_difference [as 別名]
def assertXmlFilesEqual(self, result_filename, expected_filename):
with open(result_filename) as rf:
got = rf.read()
with open(expected_filename) as ef:
want = ef.read()
checker = LXMLOutputChecker()
if not checker.check_output(want, got, 0):
message = checker.output_difference(Example("", got), want, 0)
raise AssertionError(message)
示例8: assertXmlEquivalent
# 需要導入模塊: from lxml.doctestcompare import LXMLOutputChecker [as 別名]
# 或者: from lxml.doctestcompare.LXMLOutputChecker import output_difference [as 別名]
def assertXmlEquivalent(self, got, expect):
"""Asserts both xml parse to the same results
`got` may be an XML string or lxml Element
"""
checker = LXMLOutputChecker()
if isinstance(got, etree._Element):
got = etree.tostring(got)
if not checker.check_output(expect, got, PARSE_XML):
message = checker.output_difference(doctest.Example("", expect), got, PARSE_XML)
self.fail(message)
示例9: assertEqualXML
# 需要導入模塊: from lxml.doctestcompare import LXMLOutputChecker [as 別名]
# 或者: from lxml.doctestcompare.LXMLOutputChecker import output_difference [as 別名]
def assertEqualXML(test, expected):
output_checker = LXMLOutputChecker()
if not output_checker.check_output(expected, test, PARSE_XML):
diff = output_checker.output_difference(Example("", expected), test, PARSE_XML)
msg = diff
for line in diff.split("\n"):
if msg == diff:
msg = msg + "\nDiff summary:\n"
if "got:" in line or line.strip().startswith(('+', '-')):
msg = msg + line + "\n"
if msg == "":
msg = diff
raise AssertionError(msg)
示例10: compare_xml
# 需要導入模塊: from lxml.doctestcompare import LXMLOutputChecker [as 別名]
# 或者: from lxml.doctestcompare.LXMLOutputChecker import output_difference [as 別名]
def compare_xml(generated, expected):
"""Use doctest checking from lxml for comparing XML trees. Returns diff if the two are not the same"""
checker = LXMLOutputChecker()
class DummyDocTest():
pass
ob = DummyDocTest()
ob.want = generated
check = checker.check_output(expected, generated, PARSE_XML)
if check is False:
diff = checker.output_difference(ob, expected, PARSE_XML)
return diff
示例11: assert_xml_equal
# 需要導入模塊: from lxml.doctestcompare import LXMLOutputChecker [as 別名]
# 或者: from lxml.doctestcompare.LXMLOutputChecker import output_difference [as 別名]
def assert_xml_equal(expected_xml, got_xml, context_explanation=""):
checker = LXMLOutputChecker()
if not checker.check_output(expected_xml, got_xml, 0):
raise AssertionError(
"{context_explanation}{xml_diff}".format(
context_explanation=(
"" if not context_explanation
else "\n{0}\n".format(context_explanation)
),
xml_diff=checker.output_difference(
doctest.Example("", expected_xml),
got_xml,
0
)
)
)
示例12: assertXmlEqual
# 需要導入模塊: from lxml.doctestcompare import LXMLOutputChecker [as 別名]
# 或者: from lxml.doctestcompare.LXMLOutputChecker import output_difference [as 別名]
def assertXmlEqual(self, want, got):
checker = LXMLOutputChecker()
if not checker.check_output(want, got, 0):
message = checker.output_difference(Example("", want), got, 0)
raise AssertionError(message)
示例13: compare_xml
# 需要導入模塊: from lxml.doctestcompare import LXMLOutputChecker [as 別名]
# 或者: from lxml.doctestcompare.LXMLOutputChecker import output_difference [as 別名]
def compare_xml(expected, given, diff_format=PARSE_XML):
checker = LXMLOutputChecker()
if not checker.check_output(expected.strip(), given.strip(), PARSE_XML):
raise AssertionError(checker.output_difference(Example('', expected), given.decode('utf8'), diff_format))