summaryrefslogtreecommitdiff
path: root/tests/plugin1.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2014-11-12 06:28:12 -0500
committerNed Batchelder <ned@nedbatchelder.com>2014-11-12 06:28:12 -0500
commit2bfb7a99063911fd17d16bf0dc304546cb7b720d (patch)
treea6b5cc008b7715afcbc1673b8d4648581b4472a0 /tests/plugin1.py
parent81f5697e7cb2f5a064fd891617c0c8caf5ab21d9 (diff)
downloadpython-coveragepy-git-2bfb7a99063911fd17d16bf0dc304546cb7b720d.tar.gz
Clean up some plugin tests.
Diffstat (limited to 'tests/plugin1.py')
-rw-r--r--tests/plugin1.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/plugin1.py b/tests/plugin1.py
new file mode 100644
index 00000000..9401e327
--- /dev/null
+++ b/tests/plugin1.py
@@ -0,0 +1,46 @@
+"""Plugins for test_plugins.py to import."""
+
+import os.path
+
+import coverage
+from coverage.parser import CodeParser
+
+
+class Plugin(coverage.CoveragePlugin):
+ """A plugin to import, so that it isn't in the test's current directory."""
+
+ def file_tracer(self, filename):
+ """Trace only files named xyz.py"""
+ if "xyz.py" in filename:
+ file_tracer = FileTracer(filename)
+ return file_tracer
+
+ def file_reporter(self, filename):
+ return FileReporter(filename)
+
+
+class FileTracer(coverage.plugin.FileTracer):
+ def __init__(self, filename):
+ """xyz.py was actually sourced from ABC.zz"""
+ self._filename = filename
+ self._source_filename = os.path.join(
+ "/src",
+ os.path.basename(filename.replace("xyz.py", "ABC.zz"))
+ )
+
+ def source_filename(self):
+ return self._source_filename
+
+ def line_number_range(self, frame):
+ """Map the line number X to X05,X06,X07."""
+ lineno = frame.f_lineno
+ return lineno*100+5, lineno*100+7
+
+
+class FileReporter(coverage.plugin.FileReporter):
+ def get_parser(self, exclude=None):
+ return PluginParser()
+
+class PluginParser(CodeParser):
+ def parse_source(self):
+ return set([105, 106, 107, 205, 206, 207]), set([])