summaryrefslogtreecommitdiff
path: root/tests/test_plugins.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2015-02-26 06:34:03 -0500
committerNed Batchelder <ned@nedbatchelder.com>2015-02-26 06:34:03 -0500
commit08552fe5930212232c17509685f03b2216522aa7 (patch)
treef2957730a0e57ecad31462d955179806f6f3f24d /tests/test_plugins.py
parent7fd0385cfa5b776b4c7b10c4ff077296db005c49 (diff)
downloadpython-coveragepy-08552fe5930212232c17509685f03b2216522aa7.tar.gz
Handle exceptions from dynamic_source_filename.
This required disabling plugins from the C tracer.
Diffstat (limited to 'tests/test_plugins.py')
-rw-r--r--tests/test_plugins.py42
1 files changed, 28 insertions, 14 deletions
diff --git a/tests/test_plugins.py b/tests/test_plugins.py
index 88c653c..c827251 100644
--- a/tests/test_plugins.py
+++ b/tests/test_plugins.py
@@ -442,15 +442,30 @@ class BadPluginTest(FileTracerTest):
"""Test error handling around plugins."""
def run_bad_plugin(self, plugin_name, our_error=True):
- """Run a file, and see that the plugin failed."""
+ """Run a file, and see that the plugin failed.
+
+ `plugin_name` is the name of the plugin to use.
+
+ `our_error` is True if the error reported to the user will be an
+ explicit error in our test code, marked with an # Oh noes! comment.
+
+ """
self.make_file("simple.py", """\
- import other
- a = 2
- b = 3
+ import other, another
+ a = other.f(2)
+ b = other.f(3)
+ c = another.g(4)
+ d = another.g(5)
""")
+ # The names of these files are important: some plugins apply themselves
+ # to "*other.py".
self.make_file("other.py", """\
- x = 1
- y = 2
+ def f(x):
+ return x+1
+ """)
+ self.make_file("another.py", """\
+ def g(x):
+ return x-1
""")
cov = coverage.Coverage()
@@ -466,9 +481,9 @@ class BadPluginTest(FileTracerTest):
self.assertEqual(errors, 1)
# There should be a warning explaining what's happening, but only one.
- msg = "Disabling plugin '%s' due to an exception:" % plugin_name
- tracebacks = stderr.count(msg)
- self.assertEqual(tracebacks, 1)
+ msg = "Disabling plugin %r due to an exception:" % plugin_name
+ warnings = stderr.count(msg)
+ self.assertEqual(warnings, 1)
def test_file_tracer_fails(self):
self.make_file("bad_plugin.py", """\
@@ -527,19 +542,18 @@ class BadPluginTest(FileTracerTest):
""")
self.run_bad_plugin("bad_plugin", our_error=False)
- # This test currently crashes the C tracer function. I'm working on
- # figuring out why....
- def xxx_dynamic_source_filename_fails(self):
+ def test_dynamic_source_filename_fails(self):
self.make_file("bad_plugin.py", """\
import coverage.plugin
class Plugin(coverage.plugin.CoveragePlugin):
def file_tracer(self, filename):
- return BadFileTracer()
+ if filename.endswith("other.py"):
+ return BadFileTracer()
class BadFileTracer(coverage.plugin.FileTracer):
def has_dynamic_source_filename(self):
return True
def dynamic_source_filename(self, filename, frame):
- 101/0
+ 101/0 # Oh noes!
""")
self.run_bad_plugin("bad_plugin")