summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2018-06-27 10:55:47 -0400
committerNed Batchelder <ned@nedbatchelder.com>2018-06-27 10:57:02 -0400
commit9334303596d86d62c634c958d3fe6538b64fe4d6 (patch)
tree7186305edad9d1eed5e6f72c88d6c72c4093a823
parent8497ebc588dce9f1727321d91239fd57ed1ca558 (diff)
downloadpython-coveragepy-git-9334303596d86d62c634c958d3fe6538b64fe4d6.tar.gz
Gold files can be in versioned subdirectories
-rw-r--r--tests/test_farm.py32
1 files changed, 30 insertions, 2 deletions
diff --git a/tests/test_farm.py b/tests/test_farm.py
index 1f9a56d7..9fb48e85 100644
--- a/tests/test_farm.py
+++ b/tests/test_farm.py
@@ -179,9 +179,37 @@ def run(cmds, rundir="src", outfile=None):
fout.close()
+def versioned_directory(d):
+ """Find a subdirectory of d specific to the Python version.
+
+ For example, on Python 3.6.4 rc 1, it returns the first of these
+ directories that exists::
+
+ d/3.6.4.candidate.1
+ d/3.6.4.candidate
+ d/3.6.4
+ d/3.6
+ d/3
+ d
+
+ Returns: a string, the path to an existing directory.
+
+ """
+ ver_parts = list(map(str, sys.version_info))
+ for nparts in range(len(ver_parts), -1, -1):
+ version = ".".join(ver_parts[:nparts])
+ subdir = os.path.join(d, version)
+ if os.path.exists(subdir):
+ return subdir
+ raise Exception("Directory missing: {}".format(d)) # pragma: only failure
+
+
def compare(dir1, dir2, file_pattern=None, size_within=0, left_extra=False, scrubs=None):
"""Compare files matching `file_pattern` in `dir1` and `dir2`.
+ A version-specific subdirectory of `dir1` or `dir2` will be used if
+ it exists.
+
`size_within` is a percentage delta for the file sizes. If non-zero,
then the file contents are not compared (since they are expected to
often be different), but the file sizes must be within this amount.
@@ -198,8 +226,8 @@ def compare(dir1, dir2, file_pattern=None, size_within=0, left_extra=False, scru
matches.
"""
- assert os.path.exists(dir1), "Left directory missing: %s" % dir1
- assert os.path.exists(dir2), "Right directory missing: %s" % dir2
+ dir1 = versioned_directory(dir1)
+ dir2 = versioned_directory(dir2)
dc = filecmp.dircmp(dir1, dir2)
diff_files = fnmatch_list(dc.diff_files, file_pattern)