How to use the gcovr.utils.FilterOption function in gcovr

To help you get started, we’ve selected a few gcovr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gcovr / gcovr / gcovr / utils.py View on Github external
(suggestion, bs_count) = re.subn(
            r'\\\\|\\(?=[^\WabfnrtuUvx0-9AbBdDsSwWZ])', '/', self.regex)
        if bs_count:
            logger.warn("filters must use forward slashes as path separators")
            logger.warn("your filter : {}", self.regex)
            logger.warn("did you mean: {}", suggestion)

        if os.path.isabs(self.regex):
            return AbsoluteFilter(self.regex)
        else:
            path_context = (self.path_context if self.path_context is not None
                            else os.getcwd())
            return RelativeFilter(path_context, self.regex)


class NonEmptyFilterOption(FilterOption):
    def __init__(self, regex, path_context=None):
        if not regex:
            raise ArgumentTypeError("filter cannot be empty")
        super(NonEmptyFilterOption, self).__init__(regex, path_context)


FilterOption.NonEmpty = NonEmptyFilterOption


class Filter(object):
    def __init__(self, pattern):
        self.pattern = re.compile(pattern)

    def match(self, path):
        os_independent_path = path.replace(os.path.sep, '/')
        return self.pattern.match(os_independent_path)
github gcovr / gcovr / gcovr / configuration.py View on Github external
const=OutputOrDefault(None),
    ),
    GcovrConfigOption(
        "prettyjson", ["--json-pretty"],
        group="output_options",
        help="Pretty-print the JSON report. Implies --json. Default: {default!s}.",
        action="store_true",
    ),
    GcovrConfigOption(
        "filter", ["-f", "--filter"],
        group="filter_options",
        help="Keep only source files that match this filter. "
             "Can be specified multiple times. "
             "If no filters are provided, defaults to --root.",
        action="append",
        type=FilterOption,
        default=[],
    ),
    GcovrConfigOption(
        "exclude", ["-e", "--exclude"],
        group="filter_options",
        help="Exclude source files that match this filter. "
             "Can be specified multiple times.",
        action="append",
        type=FilterOption.NonEmpty,
        default=[],
    ),
    GcovrConfigOption(
        "gcov_filter", ["--gcov-filter"],
        group="filter_options",
        help="Keep only gcov data files that match this filter. "
             "Can be specified multiple times.",
github gcovr / gcovr / gcovr / utils.py View on Github external
if os.path.isabs(self.regex):
            return AbsoluteFilter(self.regex)
        else:
            path_context = (self.path_context if self.path_context is not None
                            else os.getcwd())
            return RelativeFilter(path_context, self.regex)


class NonEmptyFilterOption(FilterOption):
    def __init__(self, regex, path_context=None):
        if not regex:
            raise ArgumentTypeError("filter cannot be empty")
        super(NonEmptyFilterOption, self).__init__(regex, path_context)


FilterOption.NonEmpty = NonEmptyFilterOption


class Filter(object):
    def __init__(self, pattern):
        self.pattern = re.compile(pattern)

    def match(self, path):
        os_independent_path = path.replace(os.path.sep, '/')
        return self.pattern.match(os_independent_path)

    def __str__(self):
        return "{name}({pattern})".format(
            name=type(self).__name__, pattern=self.pattern.pattern)


class AbsoluteFilter(Filter):
github gcovr / gcovr / gcovr / configuration.py View on Github external
"filter", ["-f", "--filter"],
        group="filter_options",
        help="Keep only source files that match this filter. "
             "Can be specified multiple times. "
             "If no filters are provided, defaults to --root.",
        action="append",
        type=FilterOption,
        default=[],
    ),
    GcovrConfigOption(
        "exclude", ["-e", "--exclude"],
        group="filter_options",
        help="Exclude source files that match this filter. "
             "Can be specified multiple times.",
        action="append",
        type=FilterOption.NonEmpty,
        default=[],
    ),
    GcovrConfigOption(
        "gcov_filter", ["--gcov-filter"],
        group="filter_options",
        help="Keep only gcov data files that match this filter. "
             "Can be specified multiple times.",
        action="append",
        type=FilterOption,
        default=[],
    ),
    GcovrConfigOption(
        "gcov_exclude", ["--gcov-exclude"],
        group="filter_options",
        help="Exclude gcov data files that match this filter. "
             "Can be specified multiple times.",
github gcovr / gcovr / gcovr / configuration.py View on Github external
use_const = None  # marker to continue with parsing

    if use_const is True:
        return option.const
    if use_const is False:
        return option.default
    assert use_const is None

    # parse the value
    if option.type is bool:
        value = cfg_entry.value_as_bool

    elif option.type is not None:

        args = ()
        if isinstance(option.type, FilterOption):
            args = [os.path.dirname(cfg_entry.filename)]

        try:
            value = option.type(cfg_entry.value, *args)
        except (ValueError, ArgumentTypeError) as err:
            raise cfg_entry.error(str(err))

    else:
        value = cfg_entry.value

    # verify choices:
    if option.choices is not None:
        if value not in option.choices:
            raise cfg_entry.error(  # pylint: disable=raising-format-tuple
                "must be one of ({}) but got {!r}",
                ', '.join(repr(choice) for choice in option.choices),