我们从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)