summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2009-09-26 09:45:43 -0400
committerNed Batchelder <ned@nedbatchelder.com>2009-09-26 09:45:43 -0400
commit06baf4cce9f7c8fa4e8e76a7c706cda8fccb4888 (patch)
treebcbaed55812529824fd2f65a9860fda5f07dc02f
parent185efb980902b5ab726ccfd3b411140e9b3d05fa (diff)
downloadpython-coveragepy-06baf4cce9f7c8fa4e8e76a7c706cda8fccb4888.tar.gz
File comparison can include regex scrubbing to ignore certain parts.
-rw-r--r--test/test_farm.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/test/test_farm.py b/test/test_farm.py
index 01934df..a20a9a2 100644
--- a/test/test_farm.py
+++ b/test/test_farm.py
@@ -1,6 +1,6 @@
"""Run tests in the farm subdirectory. Designed for nose."""
-import difflib, filecmp, fnmatch, glob, os, shutil, sys
+import difflib, filecmp, fnmatch, glob, os, re, shutil, sys
sys.path.insert(0, os.path.split(__file__)[0]) # Force relative import for Py3k
from backtest import run_command, execfile # pylint: disable-msg=W0622
@@ -158,7 +158,7 @@ class FarmTestCase(object):
self.cd(cwd)
def compare(self, dir1, dir2, filepattern=None, size_within=0,
- left_extra=False, right_extra=False
+ left_extra=False, right_extra=False, scrubs=None
):
"""Compare files matching `filepattern` in `dir1` and `dir2`.
@@ -177,6 +177,9 @@ class FarmTestCase(object):
without triggering an assertion. `right_extra` means the right
directory can.
+ `scrubs` is a list of pairs, regex find and replace patterns to use to
+ scrub the files of unimportant differences.
+
An assertion will be raised if the directories fail one of their
matches.
@@ -220,6 +223,9 @@ class FarmTestCase(object):
for f in diff_files:
left = open(os.path.join(dir1, f), "r").readlines()
right = open(os.path.join(dir2, f), "r").readlines()
+ if scrubs:
+ left = self._scrub(left, scrubs)
+ right = self._scrub(right, scrubs)
if left != right:
text_diff.append(f)
print("".join(list(difflib.Differ().compare(left, right))))
@@ -230,6 +236,14 @@ class FarmTestCase(object):
if not right_extra:
assert not right_only, "Files in %s only: %s" % (dir2, right_only)
+ def _scrub(self, strlist, scrubs):
+ scrubbed = []
+ for s in strlist:
+ for rgx_find, rgx_replace in scrubs:
+ s = re.sub(rgx_find, rgx_replace, s)
+ scrubbed.append(s)
+ return scrubbed
+
def contains(self, filename, *strlist):
"""Check that the file contains all of a list of strings.