本文整理汇总了Python中coverage.files.FnmatchMatcher类的典型用法代码示例。如果您正苦于以下问题:Python FnmatchMatcher类的具体用法?Python FnmatchMatcher怎么用?Python FnmatchMatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FnmatchMatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
def run(self, edit):
view = self.view
view.erase_regions('SublimePythonCoverage')
fname = view.file_name()
if not fname:
return
cov_file = find(fname, '.coverage')
if not cov_file:
print('Could not find .coverage file.')
return
config_file = os.path.join(os.path.dirname(cov_file), '.coveragerc')
if find(fname, '.coverage-noisy'):
flags = sublime.DRAW_EMPTY | sublime.DRAW_OUTLINED
else:
flags = sublime.HIDDEN
# run analysis and find uncovered lines
cov = coverage(data_file=cov_file, config_file=config_file)
outlines = []
omit_matcher = FnmatchMatcher(cov.omit)
if not omit_matcher.match(fname):
cov.load()
f, s, excluded, missing, m = cov.analysis2(fname)
for line in missing:
outlines.append(view.full_line(view.text_point(line - 1, 0)))
# update highlighted regions
if outlines:
view.add_regions('SublimePythonCoverage', outlines,
'coverage.missing', 'bookmark', flags)
示例2: find_file_reporters
def find_file_reporters(self, morfs):
"""Find the FileReporters we'll report on.
`morfs` is a list of modules or file names.
"""
self.file_reporters = self.coverage._get_file_reporters(morfs)
if self.config.include:
patterns = prep_patterns(self.config.include)
matcher = FnmatchMatcher(patterns)
filtered = []
for fr in self.file_reporters:
if matcher.match(fr.filename):
filtered.append(fr)
self.file_reporters = filtered
if self.config.omit:
patterns = prep_patterns(self.config.omit)
matcher = FnmatchMatcher(patterns)
filtered = []
for fr in self.file_reporters:
if not matcher.match(fr.filename):
filtered.append(fr)
self.file_reporters = filtered
self.file_reporters.sort()
示例3: run
def run(self, edit):
view = self.view
fname = view.file_name()
if not fname:
return
cov_file = find(fname, ".coverage")
if not cov_file:
print "Could not find .coverage file."
return
# run analysis and find uncovered lines
cov = coverage(data_file=cov_file)
outlines = []
omit_matcher = FnmatchMatcher(cov.omit)
if not omit_matcher.match(fname):
cov_dir = os.path.dirname(cov_file)
os.chdir(cov_dir)
relpath = os.path.relpath(fname, cov_dir)
cov.load()
f, s, excluded, missing, m = cov.analysis2(relpath)
for line in missing:
outlines.append(view.full_line(view.text_point(line - 1, 0)))
# update highlighted regions
view.erase_regions("SublimePythonCoverage")
if outlines:
view.add_regions("SublimePythonCoverage", outlines, "comment", sublime.DRAW_EMPTY | sublime.DRAW_OUTLINED)
示例4: start
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
示例5: find_code_units
def find_code_units(self, morfs):
"""Find the code units we'll report on.
`morfs` is a list of modules or filenames.
"""
morfs = morfs or self.coverage.data.measured_files()
file_locator = self.coverage.file_locator
get_ext = self.coverage.data.extension_data().get
self.code_units = code_unit_factory(morfs, file_locator, get_ext)
if self.config.include:
patterns = prep_patterns(self.config.include)
matcher = FnmatchMatcher(patterns)
filtered = []
for cu in self.code_units:
if matcher.match(cu.filename):
filtered.append(cu)
self.code_units = filtered
if self.config.omit:
patterns = prep_patterns(self.config.omit)
matcher = FnmatchMatcher(patterns)
filtered = []
for cu in self.code_units:
if not matcher.match(cu.filename):
filtered.append(cu)
self.code_units = filtered
self.code_units.sort()
示例6: run
def run(self, edit):
view = self.view
fname = view.file_name()
if not fname:
return
cov_file = find(fname, '.coverage')
if not cov_file:
print 'Could not find .coverage file.'
return
# run analysis and find uncovered lines
cov = coverage(data_file=cov_file)
outlines = []
omit_matcher = FnmatchMatcher(cov.omit)
if not omit_matcher.match(fname):
cov_dir = os.path.dirname(cov_file)
os.chdir(cov_dir)
relpath = os.path.relpath(fname, cov_dir)
cov.load()
f, s, excluded, missing, m = cov.analysis2(relpath)
for line in missing:
outlines.append(view.full_line(view.text_point(line - 1, 0)))
# update highlighted regions
view.erase_regions('SublimePythonCoverage')
if outlines:
view.add_regions('SublimePythonCoverage', outlines,
'markup.inserted', 'bookmark', sublime.HIDDEN)
示例7: test_fnmatch_matcher
def test_fnmatch_matcher(self):
matches_to_try = [
(self.make_file("sub/file1.py"), True),
(self.make_file("sub/file2.c"), False),
(self.make_file("sub2/file3.h"), True),
(self.make_file("sub3/file4.py"), True),
(self.make_file("sub3/file5.c"), False),
]
fnm = FnmatchMatcher(["*.py", "*/sub2/*"])
self.assertEqual(fnm.info(), ["*.py", "*/sub2/*"])
for filepath, matches in matches_to_try:
self.assertMatches(fnm, filepath, matches)
示例8: test_fnmatch_matcher
def test_fnmatch_matcher(self):
file1 = self.make_file("sub/file1.py")
file2 = self.make_file("sub/file2.c")
file3 = self.make_file("sub2/file3.h")
file4 = self.make_file("sub3/file4.py")
file5 = self.make_file("sub3/file5.c")
fl = FileLocator()
fnm = FnmatchMatcher(["*.py", "*/sub2/*"])
self.assertTrue(fnm.match(fl.canonical_filename(file1)))
self.assertFalse(fnm.match(fl.canonical_filename(file2)))
self.assertTrue(fnm.match(fl.canonical_filename(file3)))
self.assertTrue(fnm.match(fl.canonical_filename(file4)))
self.assertFalse(fnm.match(fl.canonical_filename(file5)))
示例9: find_file_reporters
def find_file_reporters(self, morfs):
"""Find the FileReporters we'll report on.
`morfs` is a list of modules or file names.
"""
reporters = self.coverage._get_file_reporters(morfs)
if self.config.include:
matcher = FnmatchMatcher(prep_patterns(self.config.include))
reporters = [fr for fr in reporters if matcher.match(fr.filename)]
if self.config.omit:
matcher = FnmatchMatcher(prep_patterns(self.config.omit))
reporters = [fr for fr in reporters if not matcher.match(fr.filename)]
self.file_reporters = sorted(reporters)
示例10: start
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)
# The user may want to debug things, show info if desired.
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
示例11: Coverage
#.........这里部分代码省略.........
structseq_file = structseq_new.func_code.co_filename
except AttributeError:
structseq_file = structseq_new.__code__.co_filename
self.pylib_dirs.add(self._canonical_dir(structseq_file))
# To avoid tracing the coverage.py code itself, we skip anything
# located where we are.
self.cover_dirs = [self._canonical_dir(__file__)]
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.
示例12: _init
#.........这里部分代码省略.........
", ".join(
plugin._coverage_plugin_name
for plugin in self.plugins.file_tracers
),
self.collector.tracer_name(),
)
)
for plugin in self.plugins.file_tracers:
plugin._coverage_enabled = False
# Suffixes are a bit tricky. We want to use the data suffix only when
# collecting data, not when combining data. So we save it as
# `self.run_suffix` now, and promote it to `self.data_suffix` if we
# find that we are collecting data later.
if self._data_suffix or self.config.parallel:
if not isinstance(self._data_suffix, string_class):
# if data_suffix=True, use .machinename.pid.random
self._data_suffix = True
else:
self._data_suffix = None
self.data_suffix = None
self.run_suffix = self._data_suffix
# Create the data file. We do this at construction time so that the
# 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, warn=self._warn)
# The directories for files considered "installed with the interpreter".
self.pylib_dirs = set()
if not self.config.cover_pylib:
# Look at where some standard modules are located. That's the
# indication for "installed with the interpreter". In some
# 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, 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__'):
# PyPy 2.4 has no __file__ in the builtin modules, but the code
# objects still have the file names. So dig into one to find
# the path to exclude.
structseq_new = _structseq.structseq_new
try:
structseq_file = structseq_new.func_code.co_filename
except AttributeError:
structseq_file = structseq_new.__code__.co_filename
self.pylib_dirs.add(self._canonical_dir(structseq_file))
# To avoid tracing the coverage.py code itself, we skip anything
# located where we are.
self.cover_dirs = [self._canonical_dir(__file__)]
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", ())
示例13: Coverage
#.........这里部分代码省略.........
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)
# The user may want to debug things, show info if desired.
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):
"""Stop measuring code coverage."""
self._started = False
self.collector.stop()
def _atexit(self):
"""Clean up on process shutdown."""
if self._started:
self.stop()
if self.auto_data:
self.save()
def erase(self):
"""Erase previously-collected coverage data.
示例14: coverage
#.........这里部分代码省略.........
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()
def _atexit(self):
if self._started:
self.stop()
if self.auto_data:
self.save()
def erase(self):
self.collector.reset()
self.data.erase()
def clear_exclude(self, which = 'exclude'):
setattr(self.config, which + '_list', [])
self._exclude_regex_stale()
def exclude(self, regex, which = 'exclude'):
示例15: configure
def configure(self, config):
"""Apply the configuration to get ready for decision-time."""
for src in config.source or []:
if os.path.isdir(src):
self.source.append(canonical_filename(src))
else:
self.source_pkgs.append(src)
self.source_pkgs_unmatched = self.source_pkgs[:]
self.omit = prep_patterns(config.run_omit)
self.include = prep_patterns(config.run_include)
# The directories for files considered "installed with the interpreter".
self.pylib_paths = set()
if not config.cover_pylib:
# Look at where some standard modules are located. That's the
# indication for "installed with the interpreter". In some
# 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, _pypy_irc_topic, re, _structseq, traceback):
if m is not None and hasattr(m, "__file__"):
self.pylib_paths.add(canonical_path(m, directory=True))
if _structseq and not hasattr(_structseq, '__file__'):
# PyPy 2.4 has no __file__ in the builtin modules, but the code
# objects still have the file names. So dig into one to find
# the path to exclude. The "filename" might be synthetic,
# don't be fooled by those.
structseq_new = _structseq.structseq_new
try:
structseq_file = structseq_new.func_code.co_filename
except AttributeError:
structseq_file = structseq_new.__code__.co_filename
if not structseq_file.startswith("<"):
self.pylib_paths.add(canonical_path(structseq_file))
# To avoid tracing the coverage.py code itself, we skip anything
# located where we are.
self.cover_paths = [canonical_path(__file__, directory=True)]
if env.TESTING:
# Don't include our own test code.
self.cover_paths.append(os.path.join(self.cover_paths[0], "tests"))
# 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
import six
for mod in [contracts, six]:
self.cover_paths.append(canonical_path(mod))
# 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_paths:
self.cover_match = TreeMatcher(self.cover_paths)
if self.pylib_paths:
self.pylib_match = TreeMatcher(self.pylib_paths)
if self.include:
self.include_match = FnmatchMatcher(self.include)
if self.omit:
self.omit_match = FnmatchMatcher(self.omit)