当前位置: 首页>>代码示例>>Python>>正文


Python FnmatchMatcher.match方法代码示例

本文整理汇总了Python中coverage.files.FnmatchMatcher.match方法的典型用法代码示例。如果您正苦于以下问题:Python FnmatchMatcher.match方法的具体用法?Python FnmatchMatcher.match怎么用?Python FnmatchMatcher.match使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在coverage.files.FnmatchMatcher的用法示例。


在下文中一共展示了FnmatchMatcher.match方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: find_file_reporters

# 需要导入模块: from coverage.files import FnmatchMatcher [as 别名]
# 或者: from coverage.files.FnmatchMatcher import match [as 别名]
    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()
开发者ID:pycom,项目名称:EricShort,代码行数:29,代码来源:report.py

示例2: find_code_units

# 需要导入模块: from coverage.files import FnmatchMatcher [as 别名]
# 或者: from coverage.files.FnmatchMatcher import match [as 别名]
    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()
开发者ID:brifordwylie,项目名称:coveragepy,代码行数:32,代码来源:report.py

示例3: test_fnmatch_matcher

# 需要导入模块: from coverage.files import FnmatchMatcher [as 别名]
# 或者: from coverage.files.FnmatchMatcher import match [as 别名]
 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)))
开发者ID:nveiseh,项目名称:apimedf,代码行数:15,代码来源:test_files.py

示例4: run

# 需要导入模块: from coverage.files import FnmatchMatcher [as 别名]
# 或者: from coverage.files.FnmatchMatcher import match [as 别名]
    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)
开发者ID:niclas-ahden,项目名称:SublimePythonCoverage,代码行数:30,代码来源:SublimePythonCoverage.py

示例5: run

# 需要导入模块: from coverage.files import FnmatchMatcher [as 别名]
# 或者: from coverage.files.FnmatchMatcher import match [as 别名]
    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)
开发者ID:zehome,项目名称:SublimePythonCoverage,代码行数:35,代码来源:SublimePythonCoverage.py

示例6: run

# 需要导入模块: from coverage.files import FnmatchMatcher [as 别名]
# 或者: from coverage.files.FnmatchMatcher import match [as 别名]
    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)
开发者ID:imposeren,项目名称:SublimePythonCoverage,代码行数:31,代码来源:SublimePythonCoverage.py

示例7: find_file_reporters

# 需要导入模块: from coverage.files import FnmatchMatcher [as 别名]
# 或者: from coverage.files.FnmatchMatcher import match [as 别名]
    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)
开发者ID:blueyed,项目名称:coveragepy,代码行数:19,代码来源:report.py

示例8: Coverage

# 需要导入模块: from coverage.files import FnmatchMatcher [as 别名]
# 或者: from coverage.files.FnmatchMatcher import match [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,
        concurrency=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 configuration file to read:

            * If it is ".coveragerc", it is interpreted as if it were True,
              for backward compatibility.

            * If it is a string, it is the name of the file to read.  If the
              file can't be read, it is an error.

            * If it is True, then a few standard files names are tried
              (".coveragerc", "setup.cfg").  It is not an error for these files
              to not be found.

            * If it is False, then no configuration 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 file name 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.

        `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",
        "multiprocessing", or "thread" (the default).

        .. versionadded:: 4.0
            The `concurrency` parameter.

        """
        # Build our configuration from a number of sources:
        # 1: defaults:
        self.config = CoverageConfig()

        # 2: from the rcfile, .coveragerc or setup.cfg file:
        if config_file:
            did_read_rc = False
            # Some API users were specifying ".coveragerc" to mean the same as
            # True, so make it so.
            if config_file == ".coveragerc":
                config_file = True
            specified_file = (config_file is not True)
            if not specified_file:
                config_file = ".coveragerc"

            did_read_rc = self.config.from_file(config_file)

            if not did_read_rc:
                if specified_file:
                    raise CoverageException(
                        "Couldn't read '%s' as a config file" % config_file
                        )
                self.config.from_file("setup.cfg", section_prefix="coverage:")

        # 3: from environment variables:
#.........这里部分代码省略.........
开发者ID:Athsheep,项目名称:Flask_Web_Development,代码行数:103,代码来源:control.py

示例9: Coverage

# 需要导入模块: from coverage.files import FnmatchMatcher [as 别名]
# 或者: from coverage.files.FnmatchMatcher import match [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,
#.........这里部分代码省略.........
开发者ID:fabio-ts,项目名称:unftt,代码行数:103,代码来源:control.py

示例10: coverage

# 需要导入模块: from coverage.files import FnmatchMatcher [as 别名]
# 或者: from coverage.files.FnmatchMatcher import match [as 别名]
class coverage(object):

    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):
        from coverage import __version__
        self._warnings = []
        self.config = CoverageConfig()
        if config_file:
            if config_file is True:
                config_file = '.coveragerc'
            try:
                self.config.from_file(config_file)
            except ValueError:
                _, err, _ = sys.exc_info()
                raise CoverageException("Couldn't read config file %s: %s" % (config_file, err))

        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
        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)
        self.debug = DebugControl(self.config.debug, debug_file or sys.stderr)
        self.auto_data = auto_data
        self._exclude_re = {}
        self._exclude_regex_stale()
        self.file_locator = FileLocator()
        self.source = []
        self.source_pkgs = []
        for src in self.config.source or []:
            if os.path.exists(src):
                self.source.append(self.file_locator.canonical_filename(src))
            else:
                self.source_pkgs.append(src)

        self.omit = prep_patterns(self.config.omit)
        self.include = prep_patterns(self.config.include)
        self.collector = Collector(self._should_trace, timid=self.config.timid, branch=self.config.branch, warn=self._warn)
        if data_suffix or self.config.parallel:
            if not isinstance(data_suffix, string_class):
                data_suffix = True
        else:
            data_suffix = None
        self.data_suffix = None
        self.run_suffix = data_suffix
        self.data = CoverageData(basename=self.config.data_file, collector='coverage v%s' % __version__, debug=self.debug)
        self.pylib_dirs = []
        if not self.config.cover_pylib:
            for m in (atexit,
             os,
             random,
             socket,
             _structseq):
                if m is not None and hasattr(m, '__file__'):
                    m_dir = self._canonical_dir(m)
                    if m_dir not in self.pylib_dirs:
                        self.pylib_dirs.append(m_dir)

        self.cover_dir = self._canonical_dir(__file__)
        self.source_match = None
        self.pylib_match = self.cover_match = None
        self.include_match = self.omit_match = None
        Numbers.set_precision(self.config.precision)
        self._warn_no_data = True
        self._warn_unimported_source = True
        self._started = False
        self._measured = False
        atexit.register(self._atexit)

    def _canonical_dir(self, morf):
        return os.path.split(CodeUnit(morf, self.file_locator).filename)[0]

    def _source_for_file(self, filename):
        if not filename.endswith('.py'):
            if filename[-4:-1] == '.py':
                filename = filename[:-1]
            elif filename.endswith('$py.class'):
                filename = filename[:-9] + '.py'
        return filename

    def _should_trace_with_reason(self, filename, frame):
        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):
#.........这里部分代码省略.........
开发者ID:connoryang,项目名称:dec-eve-serenity,代码行数:103,代码来源:control.py

示例11: InOrOut

# 需要导入模块: from coverage.files import FnmatchMatcher [as 别名]
# 或者: from coverage.files.FnmatchMatcher import match [as 别名]
class InOrOut(object):
    """Machinery for determining what files to measure."""

    def __init__(self, warn):
        self.warn = warn

        # The matchers for should_trace.
        self.source_match = None
        self.source_pkgs_match = None
        self.pylib_paths = self.cover_paths = None
        self.pylib_match = self.cover_match = None
        self.include_match = self.omit_match = None
        self.plugins = []
        self.disp_class = FileDisposition

        # The source argument can be directories or package names.
        self.source = []
        self.source_pkgs = []
        self.source_pkgs_unmatched = []
        self.omit = self.include = None

    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)

    def should_trace(self, filename, frame=None):
        """Decide whether to trace execution in `filename`, with a reason.

        This function is called from the trace function.  As each new file name
        is encountered, this function determines whether it is traced or not.

        Returns a FileDisposition object.

        """
        original_filename = filename
        disp = disposition_init(self.disp_class, filename)

        def nope(disp, reason):
#.........这里部分代码省略.........
开发者ID:hugovk,项目名称:coveragepy,代码行数:103,代码来源:inorout.py


注:本文中的coverage.files.FnmatchMatcher.match方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。