diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2009-11-21 09:58:22 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2009-11-21 09:58:22 -0500 |
commit | 6f4a40d34152b7d99be35f4127e76c8beb4d6c06 (patch) | |
tree | 586ae719072019768086efec991041f175291ecf /test/coveragetest.py | |
parent | ee2ceb2aba2b71ac0e262fcffa808eae9624d090 (diff) | |
download | python-coveragepy-git-6f4a40d34152b7d99be35f4127e76c8beb4d6c06.tar.gz |
Add a multiline test assert, lifted from Py3.1
Diffstat (limited to 'test/coveragetest.py')
-rw-r--r-- | test/coveragetest.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/test/coveragetest.py b/test/coveragetest.py index d1631a3d..b86794d4 100644 --- a/test/coveragetest.py +++ b/test/coveragetest.py @@ -1,6 +1,6 @@ """Base test case class for coverage testing.""" -import imp, os, random, re, shutil, sys, tempfile, textwrap, unittest +import difflib, imp, os, random, re, shutil, sys, tempfile, textwrap, unittest import coverage from coverage.backward import set, sorted, StringIO # pylint: disable-msg=W0622 @@ -280,3 +280,20 @@ class CoverageTest(unittest.TestCase): m = re.search(regex, s) if not m: raise self.failureException("%r doesn't match %r" % (s, regex)) + + def assert_multiline_equal(self, first, second): + """Assert that two multi-line strings are equal. + + If they aren't, show a nice diff. + + """ + # Adapted from Py3.1 unittest. + self.assert_(isinstance(first, str), ( + 'First argument is not a string')) + self.assert_(isinstance(second, str), ( + 'Second argument is not a string')) + + if first != second: + msg = ''.join(difflib.ndiff(first.splitlines(True), + second.splitlines(True))) + self.fail("Multi-line strings are unequal:\n" + msg) |