--- a/DebugClients/Python3/coverage/control.py Sat Jul 23 13:33:54 2016 +0200 +++ b/DebugClients/Python3/coverage/control.py Sun Jul 24 12:01:01 2016 +0200 @@ -7,6 +7,7 @@ import inspect import os import platform +import re import sys import traceback @@ -22,7 +23,7 @@ from coverage.files import ModuleMatcher, abs_file from coverage.html import HtmlReporter from coverage.misc import CoverageException, bool_or_none, join_regex -from coverage.misc import file_be_gone +from coverage.misc import file_be_gone, isolate_module from coverage.monkey import patch_multiprocessing from coverage.plugin import FileReporter from coverage.plugin_support import Plugins @@ -31,6 +32,7 @@ from coverage.summary import SummaryReporter from coverage.xmlreport import XmlReporter +os = isolate_module(os) # Pypy has some unusual stuff in the "stdlib". Consider those locations # when deciding where the stdlib is. @@ -108,8 +110,8 @@ `concurrency` is a string indicating the concurrency library being used in the measured code. Without this, coverage.py will get incorrect - results. Valid strings are "greenlet", "eventlet", "gevent", or - "thread" (the default). + results. Valid strings are "greenlet", "eventlet", "gevent", + "multiprocessing", or "thread" (the default). .. versionadded:: 4.0 The `concurrency` parameter. @@ -279,7 +281,7 @@ # data file will be written into the directory where the process # started rather than wherever the process eventually chdir'd to. self.data = CoverageData(debug=self.debug) - self.data_files = CoverageDataFiles(basename=self.config.data_file) + self.data_files = CoverageDataFiles(basename=self.config.data_file, warn=self._warn) # The directories for files considered "installed with the interpreter". self.pylib_dirs = set() @@ -289,7 +291,7 @@ # 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 +477,11 @@ # 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" @@ -798,7 +805,7 @@ """ self._init() if not self._measured: - return + return self.data self.collector.save_data(self.data) @@ -832,15 +839,6 @@ self.data.touch_file(py_file) - # Add run information. - self.data.add_run_info( - brief_sys=" ".join([ - platform.python_implementation(), - platform.python_version(), - platform.system(), - ]) - ) - if self.config.note: self.data.add_run_info(note=self.config.note) @@ -943,9 +941,9 @@ return file_reporters def report( - self, morfs=None, show_missing=True, ignore_errors=None, + self, morfs=None, show_missing=None, ignore_errors=None, file=None, # pylint: disable=redefined-builtin - omit=None, include=None, skip_covered=False, + omit=None, include=None, skip_covered=None, ): """Write a summary report to `file`. @@ -1049,7 +1047,10 @@ output_dir = os.path.dirname(self.config.xml_output) if output_dir and not os.path.isdir(output_dir): os.makedirs(output_dir) - outfile = open(self.config.xml_output, "w") + open_kwargs = {} + if env.PY3: + open_kwargs['encoding'] = 'utf8' + outfile = open(self.config.xml_output, "w", **open_kwargs) file_to_close = outfile try: reporter = XmlReporter(self, self.config) @@ -1165,11 +1166,14 @@ import coverage; coverage.process_startup() + Returns the :class:`Coverage` instance that was started, or None if it was + not started by this call. + """ cps = os.environ.get("COVERAGE_PROCESS_START") if not cps: # No request for coverage, nothing to do. - return + return None # This function can be called more than once in a process. This happens # because some virtualenv configurations make the same directory visible @@ -1184,10 +1188,12 @@ if hasattr(process_startup, "done"): # We've annotated this function before, so we must have already # started coverage.py in this process. Nothing to do. - return + return None process_startup.done = True cov = Coverage(config_file=cps, auto_data=True) cov.start() cov._warn_no_data = False cov._warn_unimported_source = False + + return cov