diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2011-08-07 22:09:40 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2011-08-07 22:09:40 -0400 |
commit | cbf42dc7273bfb828c8124c7b7229be15c15b202 (patch) | |
tree | b400724c25b029f2165f410c45339b5a16863019 /coverage/fullcoverage/encodings.py | |
parent | 06e4538fca309d796d6e8f899bcad74146a96ff3 (diff) | |
download | python-coveragepy-git-cbf42dc7273bfb828c8124c7b7229be15c15b202.tar.gz |
An enormous hack to try to get stdlib measurement from the very beginning of the process.
Diffstat (limited to 'coverage/fullcoverage/encodings.py')
-rw-r--r-- | coverage/fullcoverage/encodings.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/coverage/fullcoverage/encodings.py b/coverage/fullcoverage/encodings.py new file mode 100644 index 00000000..48b2b2e0 --- /dev/null +++ b/coverage/fullcoverage/encodings.py @@ -0,0 +1,41 @@ +"""Imposter encodings module that installs a coverage-style tracer. + +This is NOT the encodings module; it is an imposter that sets up tracing +instrumentation and then replaces itself with the real encodings module. + +If the directory that holds this file is placed first in the PYTHONPATH when +using "coverage" to run Python's tests, then this file will become the very +first module imported by the internals of Python 3. It installs a +coverage-compatible trace function that can watch Standard Library modules +execute from the very earliest stages of Python's own boot process. This fixes +a problem with coverage - that it starts too late to trace the coverage of many +of the most fundamental modules in the Standard Library. + +""" + +import sys + +class FullCoverageTracer(object): + def __init__(self): + self.traces = [] + + def fullcoverage_trace(self, *args): + frame, event, arg = args + #if "os.py" in frame.f_code.co_filename: + # print("%s @ %d" % (frame.f_code.co_filename, frame.f_lineno)) + self.traces.append(args) + return self.fullcoverage_trace + +sys.settrace(FullCoverageTracer().fullcoverage_trace) + +# Finally, remove our own directory from sys.path; remove ourselves from +# sys.modules; and re-import "encodings", which will be the real package +# this time. Note that the delete from sys.modules dictionary has to +# happen last, since all of the symbols in this module will become None +# at that exact moment, including "sys". + +import os +this = os.path.dirname(__file__) +sys.path.remove(this) +del sys.modules['encodings'] +import encodings |