summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coverage/annotate.py3
-rw-r--r--test/farm/annotate/annotate_dir.py8
-rw-r--r--test/farm/annotate/gold_anno_dir/a.py,cover5
-rw-r--r--test/farm/annotate/gold_anno_dir/b.py,cover2
-rw-r--r--test/farm/annotate/gold_anno_dir/multi.py,cover5
-rw-r--r--test/test_farm.py16
6 files changed, 35 insertions, 4 deletions
diff --git a/coverage/annotate.py b/coverage/annotate.py
index 7cf48aa2..c7ef7fe0 100644
--- a/coverage/annotate.py
+++ b/coverage/annotate.py
@@ -28,8 +28,11 @@ class AnnotateReporter(Reporter):
raise
def annotate_file(self, filename, statements, excluded, missing):
+ print "annotate_file(%r), self.dir=%r" % (filename, self.directory)
source = open(filename, 'r')
if self.directory:
+ if not os.path.exists(self.directory):
+ os.makedirs(self.directory)
dest_file = os.path.join(self.directory,
os.path.basename(filename)
+ ',cover')
diff --git a/test/farm/annotate/annotate_dir.py b/test/farm/annotate/annotate_dir.py
new file mode 100644
index 00000000..23dfff30
--- /dev/null
+++ b/test/farm/annotate/annotate_dir.py
@@ -0,0 +1,8 @@
+copy("src", "run")
+run("""
+ coverage -x multi.py
+ coverage -a -d out_anno_dir
+ """, rundir="run")
+compare("run/out_anno_dir", "gold_anno_dir", "*,cover", left_extra=True)
+clean("out_anno_dir")
+clean("run")
diff --git a/test/farm/annotate/gold_anno_dir/a.py,cover b/test/farm/annotate/gold_anno_dir/a.py,cover
new file mode 100644
index 00000000..0c858f41
--- /dev/null
+++ b/test/farm/annotate/gold_anno_dir/a.py,cover
@@ -0,0 +1,5 @@
+> def a(x):
+> if x == 1:
+> print "x is 1"
+! else:
+! print "x is not 1"
diff --git a/test/farm/annotate/gold_anno_dir/b.py,cover b/test/farm/annotate/gold_anno_dir/b.py,cover
new file mode 100644
index 00000000..0bd04dac
--- /dev/null
+++ b/test/farm/annotate/gold_anno_dir/b.py,cover
@@ -0,0 +1,2 @@
+> def b(x):
+> print "x is %s" % x
diff --git a/test/farm/annotate/gold_anno_dir/multi.py,cover b/test/farm/annotate/gold_anno_dir/multi.py,cover
new file mode 100644
index 00000000..fc5b0b79
--- /dev/null
+++ b/test/farm/annotate/gold_anno_dir/multi.py,cover
@@ -0,0 +1,5 @@
+> import a.a
+> import b.b
+
+> a.a.a(1)
+> b.b.b(2)
diff --git a/test/test_farm.py b/test/test_farm.py
index 88f7d878..f6f646f6 100644
--- a/test/test_farm.py
+++ b/test/test_farm.py
@@ -130,7 +130,9 @@ class FarmTestCase(object):
finally:
self.cd(cwd)
- def compare(self, dir1, dir2, filepattern=None):
+ def compare(self, dir1, dir2, filepattern=None, left_extra=False,
+ right_extra=False
+ ):
"""Compare files matching `filepattern` in `dir1` and `dir2`.
`dir2` is interpreted as a prefix, with Python version numbers appended
@@ -138,6 +140,10 @@ class FarmTestCase(object):
"foo_v241", "foo_v24", "foo_v2", or "foo", depending on which directory
is found first.
+ `left_extra` true means the left directory can have extra files in it
+ without triggering an assertion. `right_extra` means the right
+ directory can.
+
An assertion will be raised if the directories don't match in some way.
"""
@@ -159,8 +165,10 @@ class FarmTestCase(object):
right_only = self.fnmatch_list(dc.right_only, filepattern)
assert not diff_files, "Files differ: %s" % (diff_files)
- assert not left_only, "Files in %s only: %s" % (dir1, left_only)
- assert not right_only, "Files in %s only: %s" % (dir2, right_only)
+ if not left_extra:
+ assert not left_only, "Files in %s only: %s" % (dir1, left_only)
+ if not right_extra:
+ assert not right_only, "Files in %s only: %s" % (dir2, right_only)
def clean(self, cleandir):
"""Clean `cleandir` by removing it and all its children completely."""
@@ -173,7 +181,7 @@ def main():
# Run the test for real.
case = FarmTestCase(sys.argv[2])
case()
- if op == 'out':
+ elif op == 'out':
# Run the test, but don't clean up, so we can examine the output.
case = FarmTestCase(sys.argv[2], dont_clean=True)
case()