How to use the yamlpath.enums.PathSearchMethods.EQUALS function in yamlpath

To help you get started, we’ve selected a few yamlpath 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 wwkimball / yamlpath / tests / test_func.py View on Github external
def test_create_searchterms_from_pathattributes(self):
        st = SearchTerms(False, PathSearchMethods.EQUALS, ".", "key")
        assert str(st) == str(create_searchterms_from_pathattributes(st))

        with pytest.raises(AttributeError):
            _ = create_searchterms_from_pathattributes("nothing-to-see-here")
github wwkimball / yamlpath / tests / test_enums_pathsearchmethods.py View on Github external
		(PathSearchMethods.EQUALS, "="),
		(PathSearchMethods.STARTS_WITH, "^"),
		(PathSearchMethods.GREATER_THAN, ">"),
		(PathSearchMethods.LESS_THAN, "<"),
		(PathSearchMethods.GREATER_THAN_OR_EQUAL, ">="),
		(PathSearchMethods.LESS_THAN_OR_EQUAL, "<="),
		(PathSearchMethods.REGEX, "=~"),
	])
	def test_str(self, input, output):
		assert output == str(input)
github wwkimball / yamlpath / tests / test_commands_yaml_paths.py View on Github external
from itertools import zip_longest

        content = """---
        - &value Test value
        - value
        - *value
        """
        processor = get_yaml_editor()
        yaml_file = create_temp_yaml_file(tmp_path_factory, content)
        yaml_data = get_yaml_data(processor, quiet_logger, yaml_file)
        seen_anchors = []
        assertions = ["/&value", "/[1]"]
        results = []
        for assertion, path in zip_longest(assertions, yield_children(
            quiet_logger, yaml_data,
            SearchTerms(False, PathSearchMethods.EQUALS, "*", "value"),
            PathSeperators.FSLASH, "", seen_anchors, search_anchors=True,
            include_aliases=False
        )):
            assert assertion == str(path)
github wwkimball / yamlpath / yamlpath / parser.py View on Github external
, yaml_path
                        )

                    # Invert the search
                    search_inverted = True
                    continue

                elif c == "=":
                    # Exact value match OR >=|<=
                    element_type = PathSegmentTypes.SEARCH

                    if search_method is PathSearchMethods.LESS_THAN:
                        search_method = PathSearchMethods.LESS_THAN_OR_EQUAL
                    elif search_method is PathSearchMethods.GREATER_THAN:
                        search_method = PathSearchMethods.GREATER_THAN_OR_EQUAL
                    elif search_method is PathSearchMethods.EQUALS:
                        # Allow ==
                        continue
                    elif search_method is None:
                        search_method = PathSearchMethods.EQUALS

                        if element_id:
                            search_attr = element_id
                            element_id = ""
                        else:
                            raise YAMLPathException(
                                "Missing search operand before operator, {}"
                                .format(c)
                                , yaml_path
                            )
                    else:
                        raise YAMLPathException(
github wwkimball / yamlpath / yamlpath / yamlpath.py View on Github external
raise YAMLPathException(
                                "Missing search operand before operator, {}"
                                .format(char)
                                , yaml_path
                            )
                    else:
                        raise YAMLPathException(
                            "Unsupported search operator combination at {}"
                            .format(char)
                            , yaml_path
                        )

                    continue  # pragma: no cover

                elif char == "~":
                    if search_method == PathSearchMethods.EQUALS:
                        search_method = PathSearchMethods.REGEX
                        seeking_regex_delim = True
                    else:
                        raise YAMLPathException(
                            ("Unexpected use of {} operator.  Please try =~ if"
                             + " you mean to search with a Regular"
                             + " Expression."
                            ).format(char)
                            , yaml_path
                        )

                    continue  # pragma: no cover

                elif not segment_id:
                    # All tests beyond this point require an operand
                    raise YAMLPathException(
github wwkimball / yamlpath / yamlpath / parser.py View on Github external
search_inverted = True
                    continue

                elif c == "=":
                    # Exact value match OR >=|<=
                    element_type = PathSegmentTypes.SEARCH

                    if search_method is PathSearchMethods.LESS_THAN:
                        search_method = PathSearchMethods.LESS_THAN_OR_EQUAL
                    elif search_method is PathSearchMethods.GREATER_THAN:
                        search_method = PathSearchMethods.GREATER_THAN_OR_EQUAL
                    elif search_method is PathSearchMethods.EQUALS:
                        # Allow ==
                        continue
                    elif search_method is None:
                        search_method = PathSearchMethods.EQUALS

                        if element_id:
                            search_attr = element_id
                            element_id = ""
                        else:
                            raise YAMLPathException(
                                "Missing search operand before operator, {}"
                                .format(c)
                                , yaml_path
                            )
                    else:
                        raise YAMLPathException(
                            "Unsupported search operator combination at {}"
                            .format(c)
                            , yaml_path
                        )
github wwkimball / yamlpath / yamlpath / parser.py View on Github external
raise YAMLPathException(
                                "Missing search operand before operator, {}"
                                .format(c)
                                , yaml_path
                            )
                    else:
                        raise YAMLPathException(
                            "Unsupported search operator combination at {}"
                            .format(c)
                            , yaml_path
                        )

                    continue  # pragma: no cover

                elif c == "~":
                    if search_method == PathSearchMethods.EQUALS:
                        search_method = PathSearchMethods.REGEX
                        seeking_regex_delim = True
                    else:
                        raise YAMLPathException(
                            ("Unexpected use of {} operator.  Please try =~ if"
                                + " you mean to search with a Regular"
                                + " Expression."
                            ).format(c)
                            , yaml_path
                        )

                    continue  # pragma: no cover

                elif not element_id:
                    # All tests beyond this point require an operand
                    raise YAMLPathException(
github wwkimball / yamlpath / yamlpath / func.py View on Github external
def search_matches(method: PathSearchMethods, needle: str,
                   haystack: Any) -> bool:
    """Perform a search."""
    matches: bool = False

    if method is PathSearchMethods.EQUALS:
        if isinstance(haystack, int):
            try:
                matches = haystack == int(needle)
            except ValueError:
                matches = False
        elif isinstance(haystack, float):
            try:
                matches = haystack == float(needle)
            except ValueError:
                matches = False
        else:
            matches = haystack == needle
    elif method is PathSearchMethods.STARTS_WITH:
        matches = str(haystack).startswith(needle)
    elif method is PathSearchMethods.ENDS_WITH:
        matches = str(haystack).endswith(needle)
github wwkimball / yamlpath / yamlpath / yamlpath.py View on Github external
, yaml_path
                        )

                    # Invert the search
                    search_inverted = True
                    continue

                elif char == "=":
                    # Exact value match OR >=|<=
                    segment_type = PathSegmentTypes.SEARCH

                    if search_method is PathSearchMethods.LESS_THAN:
                        search_method = PathSearchMethods.LESS_THAN_OR_EQUAL
                    elif search_method is PathSearchMethods.GREATER_THAN:
                        search_method = PathSearchMethods.GREATER_THAN_OR_EQUAL
                    elif search_method is PathSearchMethods.EQUALS:
                        # Allow ==
                        continue
                    elif search_method is None:
                        search_method = PathSearchMethods.EQUALS

                        if segment_id:
                            search_attr = segment_id
                            segment_id = ""
                        else:
                            raise YAMLPathException(
                                "Missing search operand before operator, {}"
                                .format(char)
                                , yaml_path
                            )
                    else:
                        raise YAMLPathException(