本文整理汇总了Python中coverage.debug.DebugControl.write方法的典型用法代码示例。如果您正苦于以下问题:Python DebugControl.write方法的具体用法?Python DebugControl.write怎么用?Python DebugControl.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coverage.debug.DebugControl
的用法示例。
在下文中一共展示了DebugControl.write方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Coverage
# 需要导入模块: from coverage.debug import DebugControl [as 别名]
# 或者: from coverage.debug.DebugControl import write [as 别名]
#.........这里部分代码省略.........
if env.TESTING:
# When testing, we use PyContracts, which should be considered
# part of coverage.py, and it uses six. Exclude those directories
# just as we exclude ourselves.
import contracts, six
for mod in [contracts, six]:
self.cover_dirs.append(self._canonical_dir(mod))
# Set the reporting precision.
Numbers.set_precision(self.config.precision)
atexit.register(self._atexit)
self._inited = True
# Create the matchers we need for _should_trace
if self.source or self.source_pkgs:
self.source_match = TreeMatcher(self.source)
self.source_pkgs_match = ModuleMatcher(self.source_pkgs)
else:
if self.cover_dirs:
self.cover_match = TreeMatcher(self.cover_dirs)
if self.pylib_dirs:
self.pylib_match = TreeMatcher(self.pylib_dirs)
if self.include:
self.include_match = FnmatchMatcher(self.include)
if self.omit:
self.omit_match = FnmatchMatcher(self.omit)
# The user may want to debug things, show info if desired.
wrote_any = False
if self.debug.should('config'):
config_info = sorted(self.config.__dict__.items())
self.debug.write_formatted_info("config", config_info)
wrote_any = True
if self.debug.should('sys'):
self.debug.write_formatted_info("sys", self.sys_info())
for plugin in self.plugins:
header = "sys: " + plugin._coverage_plugin_name
info = plugin.sys_info()
self.debug.write_formatted_info(header, info)
wrote_any = True
if wrote_any:
self.debug.write_formatted_info("end", ())
def _canonical_dir(self, morf):
"""Return the canonical directory of the module or file `morf`."""
morf_filename = PythonFileReporter(morf, self).filename
return os.path.split(morf_filename)[0]
def _source_for_file(self, filename):
"""Return the source file for `filename`.
Given a file name being traced, return the best guess as to the source
file to attribute it to.
"""
if filename.endswith(".py"):
# .py files are themselves source files.
return filename
elif filename.endswith((".pyc", ".pyo")):
# Bytecode files probably have source files near them.
py_filename = filename[:-1]
示例2: coverage
# 需要导入模块: from coverage.debug import DebugControl [as 别名]
# 或者: from coverage.debug.DebugControl import write [as 别名]
#.........这里部分代码省略.........
if not filename:
return (None, "empty string isn't a filename")
if filename.startswith('<'):
return (None, 'not a real filename')
self._check_for_packages()
dunder_file = frame.f_globals.get('__file__')
if dunder_file:
filename = self._source_for_file(dunder_file)
if filename.endswith('$py.class'):
filename = filename[:-9] + '.py'
canonical = self.file_locator.canonical_filename(filename)
if self.source_match:
if not self.source_match.match(canonical):
return (None, 'falls outside the --source trees')
elif self.include_match:
if not self.include_match.match(canonical):
return (None, 'falls outside the --include trees')
else:
if self.pylib_match and self.pylib_match.match(canonical):
return (None, 'is in the stdlib')
if self.cover_match and self.cover_match.match(canonical):
return (None, 'is part of coverage.py')
if self.omit_match and self.omit_match.match(canonical):
return (None, 'is inside an --omit pattern')
return (canonical, 'because we love you')
def _should_trace(self, filename, frame):
canonical, reason = self._should_trace_with_reason(filename, frame)
if self.debug.should('trace'):
if not canonical:
msg = 'Not tracing %r: %s' % (filename, reason)
else:
msg = 'Tracing %r' % (filename,)
self.debug.write(msg)
return canonical
def _warn(self, msg):
self._warnings.append(msg)
sys.stderr.write('Coverage.py warning: %s\n' % msg)
def _check_for_packages(self):
if self.source_pkgs:
found = []
for pkg in self.source_pkgs:
try:
mod = sys.modules[pkg]
except KeyError:
continue
found.append(pkg)
try:
pkg_file = mod.__file__
except AttributeError:
pkg_file = None
else:
d, f = os.path.split(pkg_file)
if f.startswith('__init__'):
pkg_file = d
else:
pkg_file = self._source_for_file(pkg_file)
pkg_file = self.file_locator.canonical_filename(pkg_file)
if not os.path.exists(pkg_file):
pkg_file = None
if pkg_file:
self.source.append(pkg_file)
示例3: Coverage
# 需要导入模块: from coverage.debug import DebugControl [as 别名]
# 或者: from coverage.debug.DebugControl import write [as 别名]
class Coverage(object):
"""Programmatic access to coverage.py.
To use::
from coverage import coverage
cov = Coverage()
cov.start()
#.. call your code ..
cov.stop()
cov.html_report(directory='covhtml')
"""
def __init__(self, data_file=None, data_suffix=None, cover_pylib=None,
auto_data=False, timid=None, branch=None, config_file=True,
source=None, omit=None, include=None, debug=None,
debug_file=None, concurrency=None, plugins=None):
"""
`data_file` is the base name of the data file to use, defaulting to
".coverage". `data_suffix` is appended (with a dot) to `data_file` to
create the final file name. If `data_suffix` is simply True, then a
suffix is created with the machine and process identity included.
`cover_pylib` is a boolean determining whether Python code installed
with the Python interpreter is measured. This includes the Python
standard library and any packages installed with the interpreter.
If `auto_data` is true, then any existing data file will be read when
coverage measurement starts, and data will be saved automatically when
measurement stops.
If `timid` is true, then a slower and simpler trace function will be
used. This is important for some environments where manipulation of
tracing functions breaks the faster trace function.
If `branch` is true, then branch coverage will be measured in addition
to the usual statement coverage.
`config_file` determines what config file to read. If it is a string,
it is the name of the config file to read. If it is True, then a
standard file is read (".coveragerc"). If it is False, then no file is
read.
`source` is a list of file paths or package names. Only code located
in the trees indicated by the file paths or package names will be
measured.
`include` and `omit` are lists of filename patterns. Files that match
`include` will be measured, files that match `omit` will not. Each
will also accept a single string argument.
`debug` is a list of strings indicating what debugging information is
desired. `debug_file` is the file to write debug messages to,
defaulting to stderr.
`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).
`plugins` TODO.
"""
from coverage import __version__
# A record of all the warnings that have been issued.
self._warnings = []
# Build our configuration from a number of sources:
# 1: defaults:
self.config = CoverageConfig()
# 2: from the .coveragerc or setup.cfg file:
if config_file:
did_read_rc = should_read_setupcfg = False
if config_file is True:
config_file = ".coveragerc"
should_read_setupcfg = True
try:
did_read_rc = self.config.from_file(config_file)
except ValueError as err:
raise CoverageException(
"Couldn't read config file %s: %s" % (config_file, err)
)
if not did_read_rc and should_read_setupcfg:
self.config.from_file("setup.cfg", section_prefix="coverage:")
# 3: from environment variables:
self.config.from_environment('COVERAGE_OPTIONS')
env_data_file = os.environ.get('COVERAGE_FILE')
if env_data_file:
self.config.data_file = env_data_file
# 4: from constructor arguments:
self.config.from_args(
data_file=data_file, cover_pylib=cover_pylib, timid=timid,
branch=branch, parallel=bool_or_none(data_suffix),
source=source, omit=omit, include=include, debug=debug,
#.........这里部分代码省略.........
示例4: Coverage
# 需要导入模块: from coverage.debug import DebugControl [as 别名]
# 或者: from coverage.debug.DebugControl import write [as 别名]
#.........这里部分代码省略.........
function is called.
"""
if self._inited:
return
self._inited = True
# Create and configure the debugging controller. COVERAGE_DEBUG_FILE
# is an environment variable, the name of a file to append debug logs
# to.
self._debug = DebugControl(self.config.debug, self._debug_file)
# _exclude_re is a dict that maps exclusion list names to compiled regexes.
self._exclude_re = {}
set_relative_directory()
# Load plugins
self._plugins = Plugins.load_plugins(self.config.plugins, self.config, self._debug)
# Run configuring plugins.
for plugin in self._plugins.configurers:
# We need an object with set_option and get_option. Either self or
# self.config will do. Choosing randomly stops people from doing
# other things with those objects, against the public API. Yes,
# this is a bit childish. :)
plugin.configure([self, self.config][int(time.time()) % 2])
def _post_init(self):
"""Stuff to do after everything is initialized."""
if not self._wrote_debug:
self._wrote_debug = True
self._write_startup_debug()
def _write_startup_debug(self):
"""Write out debug info at startup if needed."""
wrote_any = False
with self._debug.without_callers():
if self._debug.should('config'):
config_info = sorted(self.config.__dict__.items())
config_info = [(k, v) for k, v in config_info if not k.startswith('_')]
write_formatted_info(self._debug, "config", config_info)
wrote_any = True
if self._debug.should('sys'):
write_formatted_info(self._debug, "sys", self.sys_info())
for plugin in self._plugins:
header = "sys: " + plugin._coverage_plugin_name
info = plugin.sys_info()
write_formatted_info(self._debug, header, info)
wrote_any = True
if wrote_any:
write_formatted_info(self._debug, "end", ())
def _should_trace(self, filename, frame):
"""Decide whether to trace execution in `filename`.
Calls `_should_trace_internal`, and returns the FileDisposition.
"""
disp = self._inorout.should_trace(filename, frame)
if self._debug.should('trace'):
self._debug.write(disposition_debug_msg(disp))
return disp