summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2014-11-24 20:30:53 -0500
committerNed Batchelder <ned@nedbatchelder.com>2014-11-24 20:30:53 -0500
commitb0a0f00a433d7c3467d07ce7cea4cfbaaa6ae49e (patch)
tree34c48b1b92baf9ae9e64282ec38e793e2c61423d /tests
parent4354d6ee80c81d390052c15092c7c51f2318f2f6 (diff)
downloadpython-coveragepy-git-b0a0f00a433d7c3467d07ce7cea4cfbaaa6ae49e.tar.gz
Change how dynamic source filenames work in plugins.
Diffstat (limited to 'tests')
-rw-r--r--tests/plugin1.py5
-rw-r--r--tests/test_plugins.py37
2 files changed, 38 insertions, 4 deletions
diff --git a/tests/plugin1.py b/tests/plugin1.py
index 9401e327..21e64aeb 100644
--- a/tests/plugin1.py
+++ b/tests/plugin1.py
@@ -1,4 +1,4 @@
-"""Plugins for test_plugins.py to import."""
+"""A plugin for test_plugins.py to import."""
import os.path
@@ -12,8 +12,7 @@ class Plugin(coverage.CoveragePlugin):
def file_tracer(self, filename):
"""Trace only files named xyz.py"""
if "xyz.py" in filename:
- file_tracer = FileTracer(filename)
- return file_tracer
+ return FileTracer(filename)
def file_reporter(self, filename):
return FileReporter(filename)
diff --git a/tests/test_plugins.py b/tests/test_plugins.py
index 7c4986a5..f2658998 100644
--- a/tests/test_plugins.py
+++ b/tests/test_plugins.py
@@ -137,7 +137,11 @@ class PluginTest(CoverageTest):
cov.start()
cov.stop()
- def test_importing_myself(self):
+
+class FileTracerTest(CoverageTest):
+ """Tests of plugins that implement file_tracer."""
+
+ def test_plugin1(self):
if sys.platform == 'win32':
raise SkipTest("Plugin stuff is jank on windows.. fixing soon...")
@@ -162,3 +166,34 @@ class PluginTest(CoverageTest):
self.assertEqual(missing, [])
_, statements, _, _ = cov.analysis("/src/try_ABC.zz")
self.assertEqual(statements, [105, 106, 107, 205, 206, 207])
+
+ def test_plugin2(self):
+ self.make_file("render.py", """\
+ def render(filename, linenum):
+ fiddle_around = 1 # vamp until ready
+ return "[{0} @ {1}]".format(filename, linenum)
+ """)
+ self.make_file("caller.py", """\
+ from render import render
+
+ assert render("foo.html", 17) == "[foo.html @ 17]"
+ assert render("bar.html", 23) == "[bar.html @ 23]"
+ """)
+
+ cov = coverage.Coverage()
+ cov.config["run:plugins"] = ["tests.plugin2"]
+ cov.config["run:debug"] = ["trace"]
+
+ self.start_import_stop(cov, "caller")
+
+ print(self.stderr())
+ cov._harvest_data()
+ print(cov.data.line_data())
+
+ return # TODO: finish this test
+
+ _, statements, missing, _ = cov.analysis("simple.py")
+ self.assertEqual(statements, [1,2,3])
+ self.assertEqual(missing, [])
+ _, statements, _, _ = cov.analysis("/src/try_ABC.zz")
+ self.assertEqual(statements, [105, 106, 107, 205, 206, 207])