summaryrefslogtreecommitdiff
path: root/coverage/control.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2015-10-03 18:54:55 -0400
committerNed Batchelder <ned@nedbatchelder.com>2015-10-03 18:54:55 -0400
commit8fbef1db95ca65a7bec898283da350b0e0b01847 (patch)
tree17ed9ca2737b3b638914beadc2827200fcbc3eca /coverage/control.py
parenta877aaf13d9f72ee317b392c86313a3003bcb3b8 (diff)
downloadpython-coveragepy-git-8fbef1db95ca65a7bec898283da350b0e0b01847.tar.gz
Prevent pyexpat.c from being recorded as source code. #419
Diffstat (limited to 'coverage/control.py')
-rw-r--r--coverage/control.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/coverage/control.py b/coverage/control.py
index 77737181..a5741a47 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -7,6 +7,7 @@ import atexit
import inspect
import os
import platform
+import re
import sys
import traceback
@@ -289,7 +290,7 @@ class Coverage(object):
# environments (virtualenv, for example), these modules may be
# spread across a few locations. Look at all the candidate modules
# we've imported, and take all the different ones.
- for m in (atexit, inspect, os, platform, _structseq, traceback):
+ for m in (atexit, inspect, os, platform, re, _structseq, traceback):
if m is not None and hasattr(m, "__file__"):
self.pylib_dirs.add(self._canonical_dir(m))
if _structseq and not hasattr(_structseq, '__file__'):
@@ -475,6 +476,11 @@ class Coverage(object):
# can't do anything with the data later anyway.
return nope(disp, "not a real file name")
+ # pyexpat does a dumb thing, calling the trace function explicitly from
+ # C code with a C file name.
+ if re.search(r"[/\\]Modules[/\\]pyexpat.c", filename):
+ return nope(disp, "pyexpat lies about itself")
+
# Jython reports the .class file to the tracer, use the source file.
if filename.endswith("$py.class"):
filename = filename[:-9] + ".py"
@@ -805,7 +811,7 @@ class Coverage(object):
"""
self._init()
if not self._measured:
- return
+ return self.data
self.collector.save_data(self.data)