summaryrefslogtreecommitdiff
path: root/tests/plugin2.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/plugin2.py')
-rw-r--r--tests/plugin2.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/tests/plugin2.py b/tests/plugin2.py
index 1d5d9e9f..cbd2fc11 100644
--- a/tests/plugin2.py
+++ b/tests/plugin2.py
@@ -1,13 +1,15 @@
+# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
+
"""A plugin for test_plugins.py to import."""
import os.path
import coverage
-# pylint: disable=missing-docstring
-
class Plugin(coverage.CoveragePlugin):
+ """A plugin for testing."""
def file_tracer(self, filename):
if "render.py" in filename:
return RenderFileTracer()
@@ -25,7 +27,8 @@ class RenderFileTracer(coverage.plugin.FileTracer):
def dynamic_source_filename(self, filename, frame):
if frame.f_code.co_name != "render":
return None
- return frame.f_locals['filename']
+ source_filename = os.path.abspath(frame.f_locals['filename'])
+ return source_filename
def line_number_range(self, frame):
lineno = frame.f_locals['linenum']
@@ -33,8 +36,14 @@ class RenderFileTracer(coverage.plugin.FileTracer):
class FileReporter(coverage.plugin.FileReporter):
+ """A goofy file reporter."""
def statements(self):
# Goofy test arrangement: claim that the file has as many lines as the
# number in its name.
num = os.path.basename(self.filename).split(".")[0].split("_")[1]
return set(range(1, int(num)+1))
+
+
+def coverage_init(reg, options): # pylint: disable=unused-argument
+ """Called by coverage to initialize the plugins here."""
+ reg.add_file_tracer(Plugin())