本文整理汇总了Python中coverage.collector.Collector.reset方法的典型用法代码示例。如果您正苦于以下问题:Python Collector.reset方法的具体用法?Python Collector.reset怎么用?Python Collector.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coverage.collector.Collector
的用法示例。
在下文中一共展示了Collector.reset方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Coverage
# 需要导入模块: from coverage.collector import Collector [as 别名]
# 或者: from coverage.collector.Collector import reset [as 别名]
#.........这里部分代码省略.........
pkg_file = mod.__file__
except AttributeError:
pkg_file = None
else:
d, f = os.path.split(pkg_file)
if f.startswith('__init__'):
# This is actually a package, return the directory.
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)
self.source_match.add(pkg_file)
else:
self._warn("Module %s has no Python source." % pkg)
for pkg in found:
self.source_pkgs.remove(pkg)
def use_cache(self, usecache):
"""Control the use of a data file (incorrectly called a cache).
`usecache` is true or false, whether to read and write data on disk.
"""
self.data.usefile(usecache)
def load(self):
"""Load previously-collected coverage data from the data file."""
self.collector.reset()
self.data.read()
def start(self):
"""Start measuring code coverage.
Coverage measurement actually occurs in functions called after `start`
is invoked. Statements in the same scope as `start` won't be measured.
Once you invoke `start`, you must also call `stop` eventually, or your
process might not shut down cleanly.
"""
if self.run_suffix:
# Calling start() means we're running code, so use the run_suffix
# as the data_suffix when we eventually save the data.
self.data_suffix = self.run_suffix
if self.auto_data:
self.load()
# Create the matchers we need for _should_trace
if self.source or self.source_pkgs:
self.source_match = TreeMatcher(self.source)
else:
if self.cover_dir:
self.cover_match = TreeMatcher([self.cover_dir])
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)
示例2: Coverage
# 需要导入模块: from coverage.collector import Collector [as 别名]
# 或者: from coverage.collector.Collector import reset [as 别名]
#.........这里部分代码省略.........
"""Set an option in the configuration.
`option_name` is a colon-separated string indicating the section and
option name. For example, the ``branch`` option in the ``[run]``
section of the config file would be indicated with ``"run:branch"``.
`value` is the new value for the option. This should be a Python
value where appropriate. For example, use True for booleans, not the
string ``"True"``.
As an example, calling::
cov.set_option("run:branch", True)
has the same effect as this configuration file::
[run]
branch = True
.. versionadded:: 4.0
"""
self.config.set_option(option_name, value)
def use_cache(self, usecache):
"""Obsolete method."""
self._init()
if not usecache:
self._warn("use_cache(False) is no longer supported.")
def load(self):
"""Load previously-collected coverage data from the data file."""
self._init()
self.collector.reset()
self.data_files.read(self.data)
def start(self):
"""Start measuring code coverage.
Coverage measurement actually occurs in functions called after
:meth:`start` is invoked. Statements in the same scope as
:meth:`start` won't be measured.
Once you invoke :meth:`start`, you must also call :meth:`stop`
eventually, or your process might not shut down cleanly.
"""
self._init()
if self.run_suffix:
# Calling start() means we're running code, so use the run_suffix
# as the data_suffix when we eventually save the data.
self.data_suffix = self.run_suffix
if self._auto_data:
self.load()
self.collector.start()
self._started = True
self._measured = True
def stop(self):
"""Stop measuring code coverage."""
if self._started:
self.collector.stop()
self._started = False
def _atexit(self):
示例3: coverage
# 需要导入模块: from coverage.collector import Collector [as 别名]
# 或者: from coverage.collector.Collector import reset [as 别名]
#.........这里部分代码省略.........
except KeyError:
continue
found.append(pkg)
try:
pkg_file = mod.__file__
except AttributeError:
self._warn("Module %s has no Python source." % pkg)
else:
d, f = os.path.split(pkg_file)
if f.startswith('__init__.'):
# This is actually a package, return the directory.
pkg_file = d
else:
pkg_file = self._source_for_file(pkg_file)
pkg_file = self.file_locator.canonical_filename(pkg_file)
self.source.append(pkg_file)
self.source_match.add(pkg_file)
for pkg in found:
self.source_pkgs.remove(pkg)
def use_cache(self, usecache):
"""Control the use of a data file (incorrectly called a cache).
`usecache` is true or false, whether to read and write data on disk.
"""
self.data.usefile(usecache)
def load(self):
"""Load previously-collected coverage data from the data file."""
self.collector.reset()
self.data.read()
def start(self):
"""Start measuring code coverage."""
if self.run_suffix:
# Calling start() means we're running code, so use the run_suffix
# as the data_suffix when we eventually save the data.
self.data_suffix = self.run_suffix
if self.auto_data:
self.load()
# Save coverage data when Python exits.
if not self.atexit_registered:
atexit.register(self.save)
self.atexit_registered = True
# Create the matchers we need for _should_trace
if self.source or self.source_pkgs:
self.source_match = TreeMatcher(self.source)
else:
if self.cover_dir:
self.cover_match = TreeMatcher([self.cover_dir])
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)
self._harvested = False
self.collector.start()
def stop(self):
示例4: coverage
# 需要导入模块: from coverage.collector import Collector [as 别名]
# 或者: from coverage.collector.Collector import reset [as 别名]
#.........这里部分代码省略.........
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)
self.source_match.add(pkg_file)
else:
self._warn('Module %s has no Python source.' % pkg)
for pkg in found:
self.source_pkgs.remove(pkg)
def use_cache(self, usecache):
self.data.usefile(usecache)
def load(self):
self.collector.reset()
self.data.read()
def start(self):
if self.run_suffix:
self.data_suffix = self.run_suffix
if self.auto_data:
self.load()
if self.source or self.source_pkgs:
self.source_match = TreeMatcher(self.source)
else:
if self.cover_dir:
self.cover_match = TreeMatcher([self.cover_dir])
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)
if self.debug.should('config'):
self.debug.write('Configuration values:')
config_info = sorted(self.config.__dict__.items())
self.debug.write_formatted_info(config_info)
if self.debug.should('sys'):
self.debug.write('Debugging info:')
self.debug.write_formatted_info(self.sysinfo())
self.collector.start()
self._started = True
self._measured = True
def stop(self):
self._started = False
self.collector.stop()
示例5: coverage
# 需要导入模块: from coverage.collector import Collector [as 别名]
# 或者: from coverage.collector.Collector import reset [as 别名]
#.........这里部分代码省略.........
# If we aren't supposed to trace installed code, then check if this is
# near the Python standard library and skip it if so.
if not self.cover_pylib:
if canonical.startswith(self.pylib_prefix):
return False
# We exclude the coverage code itself, since a little of it will be
# measured otherwise.
if canonical.startswith(self.cover_prefix):
return False
return canonical
# To log what should_trace returns, change this to "if 1:"
if 0:
_real_should_trace = _should_trace
def _should_trace(self, filename, frame): # pylint: disable-msg=E0102
"""A logging decorator around the real _should_trace function."""
ret = self._real_should_trace(filename, frame)
print("should_trace: %r -> %r" % (filename, ret))
return ret
def use_cache(self, usecache):
"""Control the use of a data file (incorrectly called a cache).
`usecache` is true or false, whether to read and write data on disk.
"""
self.data.usefile(usecache)
def load(self):
"""Load previously-collected coverage data from the data file."""
self.collector.reset()
self.data.read()
def start(self):
"""Start measuring code coverage."""
if self.auto_data:
self.load()
# Save coverage data when Python exits.
if not self.atexit_registered:
atexit.register(self.save)
self.atexit_registered = True
self.collector.start()
def stop(self):
"""Stop measuring code coverage."""
self.collector.stop()
self._harvest_data()
def erase(self):
"""Erase previously-collected coverage data.
This removes the in-memory data collected in this session as well as
discarding the data file.
"""
self.collector.reset()
self.data.erase()
def clear_exclude(self):
"""Clear the exclude list."""
self.exclude_list = []
self.exclude_re = ""
示例6: StateForActualGivenExecution
# 需要导入模块: from coverage.collector import Collector [as 别名]
# 或者: from coverage.collector.Collector import reset [as 别名]
class StateForActualGivenExecution(object):
def __init__(self, test_runner, search_strategy, test, settings, random):
self.test_runner = test_runner
self.search_strategy = search_strategy
self.settings = settings
self.at_least_one_success = False
self.last_exception = None
self.repr_for_last_exception = None
self.falsifying_examples = ()
self.__was_flaky = False
self.random = random
self.__warned_deadline = False
self.__existing_collector = None
self.__test_runtime = None
self.__in_final_replay = False
if self.settings.deadline is None:
self.test = test
else:
@proxies(test)
def timed_test(*args, **kwargs):
self.__test_runtime = None
start = time.time()
result = test(*args, **kwargs)
runtime = (time.time() - start) * 1000
self.__test_runtime = runtime
if self.settings.deadline is not_set:
if (
not self.__warned_deadline and
runtime >= 200
):
self.__warned_deadline = True
note_deprecation((
'Test took %.2fms to run. In future the default '
'deadline setting will be 200ms, which will '
'make this an error. You can set deadline to '
'an explicit value of e.g. %d to turn tests '
'slower than this into an error, or you can set '
'it to None to disable this check entirely.') % (
runtime, ceil(runtime / 100) * 100,
))
elif runtime >= self.current_deadline:
raise DeadlineExceeded(runtime, self.settings.deadline)
return result
self.test = timed_test
self.coverage_data = CoverageData()
self.files_to_propagate = set()
if settings.use_coverage and not IN_COVERAGE_TESTS: # pragma: no cover
if Collector._collectors:
self.hijack_collector(Collector._collectors[-1])
self.collector = Collector(
branch=True,
timid=FORCE_PURE_TRACER,
should_trace=self.should_trace,
check_include=hypothesis_check_include,
concurrency='thread',
warn=escalate_warning,
)
self.collector.reset()
# Hide the other collectors from this one so it doesn't attempt to
# pause them (we're doing trace function management ourselves so
# this will just cause problems).
self.collector._collectors = []
else:
self.collector = None
@property
def current_deadline(self):
base = self.settings.deadline
if self.__in_final_replay:
return base
else:
return base * 1.25
def should_trace(self, original_filename, frame): # pragma: no cover
disp = FileDisposition()
assert original_filename is not None
disp.original_filename = original_filename
disp.canonical_filename = encoded_filepath(
canonical_filename(original_filename))
disp.source_filename = disp.canonical_filename
disp.reason = ''
disp.file_tracer = None
disp.has_dynamic_filename = False
disp.trace = hypothesis_check_include(disp.canonical_filename)
if not disp.trace:
disp.reason = 'hypothesis internal reasons'
elif self.__existing_collector is not None:
check = self.__existing_collector.should_trace(
original_filename, frame)
if check.trace:
self.files_to_propagate.add(check.canonical_filename)
return disp
def hijack_collector(self, collector): # pragma: no cover
#.........这里部分代码省略.........
示例7: Coverage
# 需要导入模块: from coverage.collector import Collector [as 别名]
# 或者: from coverage.collector.Collector import reset [as 别名]
#.........这里部分代码省略.........
"""
return self.config.get_option(option_name)
def set_option(self, option_name, value):
"""Set an option in the configuration.
`option_name` is a colon-separated string indicating the section and
option name. For example, the ``branch`` option in the ``[run]``
section of the config file would be indicated with ``"run:branch"``.
`value` is the new value for the option. This should be an
appropriate Python value. For example, use True for booleans, not the
string ``"True"``.
As an example, calling::
cov.set_option("run:branch", True)
has the same effect as this configuration file::
[run]
branch = True
.. versionadded:: 4.0
"""
self.config.set_option(option_name, value)
def load(self):
"""Load previously-collected coverage data from the data file."""
self._init()
if self._collector:
self._collector.reset()
should_skip = self.config.parallel and not os.path.exists(self.config.data_file)
if not should_skip:
self._init_data(suffix=None)
self._post_init()
if not should_skip:
self._data.read()
def _init_for_start(self):
"""Initialization for start()"""
# Construct the collector.
concurrency = self.config.concurrency or []
if "multiprocessing" in concurrency:
if not patch_multiprocessing:
raise CoverageException( # pragma: only jython
"multiprocessing is not supported on this Python"
)
patch_multiprocessing(rcfile=self.config.config_file)
# Multi-processing uses parallel for the subprocesses, so also use
# it for the main process.
self.config.parallel = True
if self.config.dynamic_context is None:
context_switchers = []
elif self.config.dynamic_context == "test_function":
context_switchers = [should_start_context_test_function]
else:
raise CoverageException(
"Don't understand dynamic_context setting: {!r}".format(self.config.dynamic_context)
)
context_switchers.extend(
plugin.dynamic_context for plugin in self._plugins.context_switchers