summaryrefslogtreecommitdiff
path: root/tests/helpers.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/helpers.py')
-rw-r--r--tests/helpers.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/helpers.py b/tests/helpers.py
new file mode 100644
index 00000000..db20d798
--- /dev/null
+++ b/tests/helpers.py
@@ -0,0 +1,25 @@
+"""Helpers for coverage.py tests."""
+
+
+class CheckUniqueFilenames(object):
+ """Asserts the uniqueness of filenames passed to a function."""
+ def __init__(self, wrapped):
+ self.filenames = set()
+ self.wrapped = wrapped
+
+ @classmethod
+ def hook(cls, cov, method_name):
+ """Replace a method with our checking wrapper."""
+ method = getattr(cov, method_name)
+ hook = cls(method)
+ setattr(cov, method_name, hook.wrapper)
+ return hook
+
+ def wrapper(self, filename, *args, **kwargs):
+ """The replacement method. Check that we don't have dupes."""
+ assert filename not in self.filenames, (
+ "Filename %r passed to %r twice" % (filename, self.wrapped)
+ )
+ self.filenames.add(filename)
+ ret = self.wrapped(filename, *args, **kwargs)
+ return ret