本文整理汇总了Python中unittest.util.safe_repr方法的典型用法代码示例。如果您正苦于以下问题:Python util.safe_repr方法的具体用法?Python util.safe_repr怎么用?Python util.safe_repr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.util
的用法示例。
在下文中一共展示了util.safe_repr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: assertHTMLEqual
# 需要导入模块: from unittest import util [as 别名]
# 或者: from unittest.util import safe_repr [as 别名]
def assertHTMLEqual(self, html1, html2, msg=None):
"""
Asserts that two HTML snippets are semantically the same.
Whitespace in most cases is ignored, and attribute ordering is not
significant. The passed-in arguments must be valid HTML.
"""
dom1 = assert_and_parse_html(self, html1, msg,
'First argument is not valid HTML:')
dom2 = assert_and_parse_html(self, html2, msg,
'Second argument is not valid HTML:')
if dom1 != dom2:
standardMsg = '%s != %s' % (
safe_repr(dom1, True), safe_repr(dom2, True))
diff = ('\n' + '\n'.join(difflib.ndiff(
six.text_type(dom1).splitlines(),
six.text_type(dom2).splitlines())))
standardMsg = self._truncateMessage(standardMsg, diff)
self.fail(self._formatMessage(msg, standardMsg))
示例2: assertHTMLEqual
# 需要导入模块: from unittest import util [as 别名]
# 或者: from unittest.util import safe_repr [as 别名]
def assertHTMLEqual(self, html1, html2, msg=None):
"""
Assert that two HTML snippets are semantically the same.
Whitespace in most cases is ignored, and attribute ordering is not
significant. The arguments must be valid HTML.
"""
dom1 = assert_and_parse_html(self, html1, msg, 'First argument is not valid HTML:')
dom2 = assert_and_parse_html(self, html2, msg, 'Second argument is not valid HTML:')
if dom1 != dom2:
standardMsg = '%s != %s' % (
safe_repr(dom1, True), safe_repr(dom2, True))
diff = ('\n' + '\n'.join(difflib.ndiff(
str(dom1).splitlines(), str(dom2).splitlines(),
)))
standardMsg = self._truncateMessage(standardMsg, diff)
self.fail(self._formatMessage(msg, standardMsg))
示例3: assertXMLEqual
# 需要导入模块: from unittest import util [as 别名]
# 或者: from unittest.util import safe_repr [as 别名]
def assertXMLEqual(self, xml1, xml2, msg=None):
"""
Assert that two XML snippets are semantically the same.
Whitespace in most cases is ignored and attribute ordering is not
significant. The arguments must be valid XML.
"""
try:
result = compare_xml(xml1, xml2)
except Exception as e:
standardMsg = 'First or second argument is not valid XML\n%s' % e
self.fail(self._formatMessage(msg, standardMsg))
else:
if not result:
standardMsg = '%s != %s' % (safe_repr(xml1, True), safe_repr(xml2, True))
diff = ('\n' + '\n'.join(
difflib.ndiff(xml1.splitlines(), xml2.splitlines())
))
standardMsg = self._truncateMessage(standardMsg, diff)
self.fail(self._formatMessage(msg, standardMsg))
示例4: assertHTMLEqual
# 需要导入模块: from unittest import util [as 别名]
# 或者: from unittest.util import safe_repr [as 别名]
def assertHTMLEqual(self, html1, html2, msg=None):
"""
Asserts that two HTML snippets are semantically the same.
Whitespace in most cases is ignored, and attribute ordering is not
significant. The passed-in arguments must be valid HTML.
"""
dom1 = assert_and_parse_html(self, html1, msg, 'First argument is not valid HTML:')
dom2 = assert_and_parse_html(self, html2, msg, 'Second argument is not valid HTML:')
if dom1 != dom2:
standardMsg = '%s != %s' % (
safe_repr(dom1, True), safe_repr(dom2, True))
diff = ('\n' + '\n'.join(difflib.ndiff(
six.text_type(dom1).splitlines(),
six.text_type(dom2).splitlines(),
)))
standardMsg = self._truncateMessage(standardMsg, diff)
self.fail(self._formatMessage(msg, standardMsg))
示例5: assertXMLEqual
# 需要导入模块: from unittest import util [as 别名]
# 或者: from unittest.util import safe_repr [as 别名]
def assertXMLEqual(self, xml1, xml2, msg=None):
"""
Asserts that two XML snippets are semantically the same.
Whitespace in most cases is ignored, and attribute ordering is not
significant. The passed-in arguments must be valid XML.
"""
try:
result = compare_xml(xml1, xml2)
except Exception as e:
standardMsg = 'First or second argument is not valid XML\n%s' % e
self.fail(self._formatMessage(msg, standardMsg))
else:
if not result:
standardMsg = '%s != %s' % (safe_repr(xml1, True), safe_repr(xml2, True))
diff = ('\n' + '\n'.join(
difflib.ndiff(
six.text_type(xml1).splitlines(),
six.text_type(xml2).splitlines(),
)
))
standardMsg = self._truncateMessage(standardMsg, diff)
self.fail(self._formatMessage(msg, standardMsg))
示例6: assertHTMLNotEqual
# 需要导入模块: from unittest import util [as 别名]
# 或者: from unittest.util import safe_repr [as 别名]
def assertHTMLNotEqual(self, html1, html2, msg=None):
"""Asserts that two HTML snippets are not semantically equivalent."""
dom1 = assert_and_parse_html(self, html1, msg,
'First argument is not valid HTML:')
dom2 = assert_and_parse_html(self, html2, msg,
'Second argument is not valid HTML:')
if dom1 == dom2:
standardMsg = '%s == %s' % (
safe_repr(dom1, True), safe_repr(dom2, True))
self.fail(self._formatMessage(msg, standardMsg))
示例7: assertXMLEqual
# 需要导入模块: from unittest import util [as 别名]
# 或者: from unittest.util import safe_repr [as 别名]
def assertXMLEqual(self, xml1, xml2, msg=None):
"""
Asserts that two XML snippets are semantically the same.
Whitespace in most cases is ignored, and attribute ordering is not
significant. The passed-in arguments must be valid XML.
"""
try:
result = compare_xml(xml1, xml2)
except Exception as e:
standardMsg = 'First or second argument is not valid XML\n%s' % e
self.fail(self._formatMessage(msg, standardMsg))
else:
if not result:
standardMsg = '%s != %s' % (safe_repr(xml1, True), safe_repr(xml2, True))
self.fail(self._formatMessage(msg, standardMsg))
示例8: assertXMLNotEqual
# 需要导入模块: from unittest import util [as 别名]
# 或者: from unittest.util import safe_repr [as 别名]
def assertXMLNotEqual(self, xml1, xml2, msg=None):
"""
Asserts that two XML snippets are not semantically equivalent.
Whitespace in most cases is ignored, and attribute ordering is not
significant. The passed-in arguments must be valid XML.
"""
try:
result = compare_xml(xml1, xml2)
except Exception as e:
standardMsg = 'First or second argument is not valid XML\n%s' % e
self.fail(self._formatMessage(msg, standardMsg))
else:
if result:
standardMsg = '%s == %s' % (safe_repr(xml1, True), safe_repr(xml2, True))
self.fail(self._formatMessage(msg, standardMsg))
示例9: assertHTMLNotEqual
# 需要导入模块: from unittest import util [as 别名]
# 或者: from unittest.util import safe_repr [as 别名]
def assertHTMLNotEqual(self, html1, html2, msg=None):
"""Assert that two HTML snippets are not semantically equivalent."""
dom1 = assert_and_parse_html(self, html1, msg, 'First argument is not valid HTML:')
dom2 = assert_and_parse_html(self, html2, msg, 'Second argument is not valid HTML:')
if dom1 == dom2:
standardMsg = '%s == %s' % (
safe_repr(dom1, True), safe_repr(dom2, True))
self.fail(self._formatMessage(msg, standardMsg))
示例10: assertXMLNotEqual
# 需要导入模块: from unittest import util [as 别名]
# 或者: from unittest.util import safe_repr [as 别名]
def assertXMLNotEqual(self, xml1, xml2, msg=None):
"""
Assert that two XML snippets are not semantically equivalent.
Whitespace in most cases is ignored and attribute ordering is not
significant. The arguments must be valid XML.
"""
try:
result = compare_xml(xml1, xml2)
except Exception as e:
standardMsg = 'First or second argument is not valid XML\n%s' % e
self.fail(self._formatMessage(msg, standardMsg))
else:
if result:
standardMsg = '%s == %s' % (safe_repr(xml1, True), safe_repr(xml2, True))
self.fail(self._formatMessage(msg, standardMsg))
示例11: assertTrue
# 需要导入模块: from unittest import util [as 别名]
# 或者: from unittest.util import safe_repr [as 别名]
def assertTrue(self, expr, msg=None):
expr = bool(expr)
assertionRecorder = self.get_result_emitter('assertionRecorder')
assertionRecorder.assert_('True', [expr], msg)
if not expr:
msg = self._formatMessage(msg, "%s is not true" % safe_repr(expr))
self.fail(msg)
示例12: assertFalse
# 需要导入模块: from unittest import util [as 别名]
# 或者: from unittest.util import safe_repr [as 别名]
def assertFalse(self, expr, msg=None):
expr = bool(expr)
assertionRecorder = self.get_result_emitter('assertionRecorder')
assertionRecorder.assert_('False', [expr], msg)
if expr:
msg = self._formatMessage(msg, "%s is not false" % safe_repr(expr))
self.fail(msg)
示例13: assertAll
# 需要导入模块: from unittest import util [as 别名]
# 或者: from unittest.util import safe_repr [as 别名]
def assertAll(self, iterable, msg=None):
"""Check for all the value in the given iterable to be True"""
if not all(iterable):
standardMsg = 'found false value in %s' % safe_repr(iterable)
self.fail(self._formatMessage(msg, standardMsg))
示例14: assertAllIn
# 需要导入模块: from unittest import util [as 别名]
# 或者: from unittest.util import safe_repr [as 别名]
def assertAllIn(self, iterable, container, msg=None):
"""Check for all the item in iterable to be in the given container"""
for member in iterable:
if member not in container:
if member not in container:
standardMsg = '%s not found in %s' % (safe_repr(member), safe_repr(container))
self.fail(self._formatMessage(msg, standardMsg))
示例15: assertAny
# 需要导入模块: from unittest import util [as 别名]
# 或者: from unittest.util import safe_repr [as 别名]
def assertAny(self, iterable, msg=None):
"""Check for at least a True value in the given iterable"""
if not any(iterable):
standardMsg = 'true value not found in %s' % safe_repr(iterable)
self.fail(self._formatMessage(msg, standardMsg))