Python unittest2 模块,html() 实例源码
我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用unittest2.html()。
def testAssertMultiLineEqual(self):
sample_text = u("""\
http://www.python.org/doc/2.3/lib/module-unittest.html
test case
A test case is the smallest unit of testing. [...]
""")
revised_sample_text = u("""\
http://www.python.org/doc/2.4.1/lib/module-unittest.html
test case
A test case is the smallest unit of testing. [...] You may provide your
own implementation that does not subclass from TestCase,of course.
""")
sample_text_error = u("""\
- http://www.python.org/doc/2.3/lib/module-unittest.html
? ^
+ http://www.python.org/doc/2.4.1/lib/module-unittest.html
? ^^^
test case
- A test case is the smallest unit of testing. [...]
+ A test case is the smallest unit of testing. [...] You may provide your
? +++++++++++++++++++++
+ own implementation that does not subclass from TestCase,of course.
""")
self.maxDiff = None
# On python 3 we skip bytestrings as they fail the string
# check. in assertMultiLineEqual
changers = [lambda x: x]
if sys.version_info[0] < 3:
changers.append(lambda x: x.encode('utf8'))
for type_changer in changers:
try:
self.assertMultiLineEqual(type_changer(sample_text),
type_changer(revised_sample_text))
except self.failureException:
e = sys.exc_info()[1]
# need to remove the first line of the error message
error_str = str(e)
if not isinstance(error_str, six.text_type):
error_str = error_str.decode('utf8')
error_lines = error_str.split(u('\n'), 1)
if len(error_lines) > 1:
error = error_lines[1]
else:
error = error_lines[0]
self.assertEqual(sample_text_error, error)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。