Python jsonschema.exceptions.best_match() Examples

The following are code examples for showing how to use jsonschema.exceptions.best_match(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: misp42splunk   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def test_oneOf_and_anyOf_are_weak_matches(self):
        """
        A property you *must* match is probably better than one you have to
        match a part of.

        """

        validator = Draft4Validator(
            {
                "minProperties" : 2,
                "anyOf" : [{"type" : "string"}, {"type" : "number"}],
                "oneOf" : [{"type" : "string"}, {"type" : "number"}],
            }
        )
        best = self.best_match(validator.iter_errors({}))
        self.assertEqual(best.validator, "minProperties") 
Example 2
Project: misp42splunk   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def test_if_the_most_relevant_error_is_anyOf_it_is_traversed(self):
        """
        If the most relevant error is an anyOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "anyOf" : [
                            {"type" : "string"},
                            {"properties" : {"bar" : {"type" : "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 3
Project: misp42splunk   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def test_if_the_most_relevant_error_is_oneOf_it_is_traversed(self):
        """
        If the most relevant error is an oneOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "oneOf" : [
                            {"type" : "string"},
                            {"properties" : {"bar" : {"type" : "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 4
Project: misp42splunk   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def test_nested_context_for_oneOf(self):
        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "oneOf" : [
                            {"type" : "string"},
                            {
                                "oneOf" : [
                                    {"type" : "string"},
                                    {
                                        "properties" : {
                                            "bar" : {"type" : "array"}
                                        },
                                    },
                                ],
                            },
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 5
Project: core   Author: getavalon   File: test_exceptions.py    MIT License 6 votes vote down vote up
def test_oneOf_and_anyOf_are_weak_matches(self):
        """
        A property you *must* match is probably better than one you have to
        match a part of.

        """

        validator = Draft4Validator(
            {
                "minProperties" : 2,
                "anyOf" : [{"type" : "string"}, {"type" : "number"}],
                "oneOf" : [{"type" : "string"}, {"type" : "number"}],
            }
        )
        best = self.best_match(validator.iter_errors({}))
        self.assertEqual(best.validator, "minProperties") 
Example 6
Project: core   Author: getavalon   File: test_exceptions.py    MIT License 6 votes vote down vote up
def test_if_the_most_relevant_error_is_anyOf_it_is_traversed(self):
        """
        If the most relevant error is an anyOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "anyOf" : [
                            {"type" : "string"},
                            {"properties" : {"bar" : {"type" : "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 7
Project: core   Author: getavalon   File: test_exceptions.py    MIT License 6 votes vote down vote up
def test_if_the_most_relevant_error_is_oneOf_it_is_traversed(self):
        """
        If the most relevant error is an oneOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "oneOf" : [
                            {"type" : "string"},
                            {"properties" : {"bar" : {"type" : "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 8
Project: core   Author: getavalon   File: test_exceptions.py    MIT License 6 votes vote down vote up
def test_nested_context_for_oneOf(self):
        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "oneOf" : [
                            {"type" : "string"},
                            {
                                "oneOf" : [
                                    {"type" : "string"},
                                    {
                                        "properties" : {
                                            "bar" : {"type" : "array"}
                                        },
                                    },
                                ],
                            },
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 9
Project: git_for_splunk   Author: ChrisYounger   File: test_exceptions.py    Apache License 2.0 6 votes vote down vote up
def test_oneOf_and_anyOf_are_weak_matches(self):
        """
        A property you *must* match is probably better than one you have to
        match a part of.

        """

        validator = Draft4Validator(
            {
                "minProperties" : 2,
                "anyOf" : [{"type" : "string"}, {"type" : "number"}],
                "oneOf" : [{"type" : "string"}, {"type" : "number"}],
            }
        )
        best = self.best_match(validator.iter_errors({}))
        self.assertEqual(best.validator, "minProperties") 
Example 10
Project: git_for_splunk   Author: ChrisYounger   File: test_exceptions.py    Apache License 2.0 6 votes vote down vote up
def test_if_the_most_relevant_error_is_anyOf_it_is_traversed(self):
        """
        If the most relevant error is an anyOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "anyOf" : [
                            {"type" : "string"},
                            {"properties" : {"bar" : {"type" : "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 11
Project: git_for_splunk   Author: ChrisYounger   File: test_exceptions.py    Apache License 2.0 6 votes vote down vote up
def test_if_the_most_relevant_error_is_oneOf_it_is_traversed(self):
        """
        If the most relevant error is an oneOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "oneOf" : [
                            {"type" : "string"},
                            {"properties" : {"bar" : {"type" : "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 12
Project: git_for_splunk   Author: ChrisYounger   File: test_exceptions.py    Apache License 2.0 6 votes vote down vote up
def test_nested_context_for_oneOf(self):
        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "oneOf" : [
                            {"type" : "string"},
                            {
                                "oneOf" : [
                                    {"type" : "string"},
                                    {
                                        "properties" : {
                                            "bar" : {"type" : "array"}
                                        },
                                    },
                                ],
                            },
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 13
Project: pyblish-rpc   Author: pyblish   File: test_exceptions.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def test_oneOf_and_anyOf_are_weak_matches(self):
        """
        A property you *must* match is probably better than one you have to
        match a part of.

        """

        validator = Draft4Validator(
            {
                "minProperties" : 2,
                "anyOf" : [{"type" : "string"}, {"type" : "number"}],
                "oneOf" : [{"type" : "string"}, {"type" : "number"}],
            }
        )
        best = self.best_match(validator.iter_errors({}))
        self.assertEqual(best.validator, "minProperties") 
Example 14
Project: pyblish-rpc   Author: pyblish   File: test_exceptions.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def test_if_the_most_relevant_error_is_anyOf_it_is_traversed(self):
        """
        If the most relevant error is an anyOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "anyOf" : [
                            {"type" : "string"},
                            {"properties" : {"bar" : {"type" : "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 15
Project: pyblish-rpc   Author: pyblish   File: test_exceptions.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def test_if_the_most_relevant_error_is_oneOf_it_is_traversed(self):
        """
        If the most relevant error is an oneOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "oneOf" : [
                            {"type" : "string"},
                            {"properties" : {"bar" : {"type" : "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 16
Project: pyblish-rpc   Author: pyblish   File: test_exceptions.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def test_nested_context_for_oneOf(self):
        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "oneOf" : [
                            {"type" : "string"},
                            {
                                "oneOf" : [
                                    {"type" : "string"},
                                    {
                                        "properties" : {
                                            "bar" : {"type" : "array"}
                                        },
                                    },
                                ],
                            },
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 17
Project: pastebin2misp   Author: renzejongman   File: test_exceptions.py    MIT License 6 votes vote down vote up
def test_oneOf_and_anyOf_are_weak_matches(self):
        """
        A property you *must* match is probably better than one you have to
        match a part of.

        """

        validator = Draft4Validator(
            {
                "minProperties": 2,
                "anyOf": [{"type": "string"}, {"type": "number"}],
                "oneOf": [{"type": "string"}, {"type": "number"}],
            }
        )
        best = self.best_match(validator.iter_errors({}))
        self.assertEqual(best.validator, "minProperties") 
Example 18
Project: pastebin2misp   Author: renzejongman   File: test_exceptions.py    MIT License 6 votes vote down vote up
def test_if_the_most_relevant_error_is_anyOf_it_is_traversed(self):
        """
        If the most relevant error is an anyOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties": {
                    "foo": {
                        "anyOf": [
                            {"type": "string"},
                            {"properties": {"bar": {"type": "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo": {"bar": 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 19
Project: pastebin2misp   Author: renzejongman   File: test_exceptions.py    MIT License 6 votes vote down vote up
def test_if_the_most_relevant_error_is_oneOf_it_is_traversed(self):
        """
        If the most relevant error is an oneOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties": {
                    "foo": {
                        "oneOf": [
                            {"type": "string"},
                            {"properties": {"bar": {"type": "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo": {"bar": 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 20
Project: pastebin2misp   Author: renzejongman   File: test_exceptions.py    MIT License 6 votes vote down vote up
def test_nested_context_for_oneOf(self):
        validator = Draft4Validator(
            {
                "properties": {
                    "foo": {
                        "oneOf": [
                            {"type": "string"},
                            {
                                "oneOf": [
                                    {"type": "string"},
                                    {
                                        "properties": {
                                            "bar": {"type": "array"},
                                        },
                                    },
                                ],
                            },
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo": {"bar": 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 21
Project: TA-thehive   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def test_oneOf_and_anyOf_are_weak_matches(self):
        """
        A property you *must* match is probably better than one you have to
        match a part of.

        """

        validator = Draft4Validator(
            {
                "minProperties" : 2,
                "anyOf" : [{"type" : "string"}, {"type" : "number"}],
                "oneOf" : [{"type" : "string"}, {"type" : "number"}],
            }
        )
        best = self.best_match(validator.iter_errors({}))
        self.assertEqual(best.validator, "minProperties") 
Example 22
Project: TA-thehive   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def test_if_the_most_relevant_error_is_anyOf_it_is_traversed(self):
        """
        If the most relevant error is an anyOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "anyOf" : [
                            {"type" : "string"},
                            {"properties" : {"bar" : {"type" : "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 23
Project: TA-thehive   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def test_if_the_most_relevant_error_is_oneOf_it_is_traversed(self):
        """
        If the most relevant error is an oneOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "oneOf" : [
                            {"type" : "string"},
                            {"properties" : {"bar" : {"type" : "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 24
Project: TA-thehive   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def test_nested_context_for_oneOf(self):
        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "oneOf" : [
                            {"type" : "string"},
                            {
                                "oneOf" : [
                                    {"type" : "string"},
                                    {
                                        "properties" : {
                                            "bar" : {"type" : "array"}
                                        },
                                    },
                                ],
                            },
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 25
Project: accelerated-data-lake   Author: aws-samples   File: test_exceptions.py    Apache License 2.0 6 votes vote down vote up
def test_oneOf_and_anyOf_are_weak_matches(self):
        """
        A property you *must* match is probably better than one you have to
        match a part of.

        """

        validator = Draft4Validator(
            {
                "minProperties": 2,
                "anyOf": [{"type": "string"}, {"type": "number"}],
                "oneOf": [{"type": "string"}, {"type": "number"}],
            }
        )
        best = self.best_match(validator.iter_errors({}))
        self.assertEqual(best.validator, "minProperties") 
Example 26
Project: accelerated-data-lake   Author: aws-samples   File: test_exceptions.py    Apache License 2.0 6 votes vote down vote up
def test_if_the_most_relevant_error_is_anyOf_it_is_traversed(self):
        """
        If the most relevant error is an anyOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties": {
                    "foo": {
                        "anyOf": [
                            {"type": "string"},
                            {"properties": {"bar": {"type": "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo": {"bar": 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 27
Project: accelerated-data-lake   Author: aws-samples   File: test_exceptions.py    Apache License 2.0 6 votes vote down vote up
def test_if_the_most_relevant_error_is_oneOf_it_is_traversed(self):
        """
        If the most relevant error is an oneOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties": {
                    "foo": {
                        "oneOf": [
                            {"type": "string"},
                            {"properties": {"bar": {"type": "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo": {"bar": 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 28
Project: accelerated-data-lake   Author: aws-samples   File: test_exceptions.py    Apache License 2.0 6 votes vote down vote up
def test_nested_context_for_oneOf(self):
        validator = Draft4Validator(
            {
                "properties": {
                    "foo": {
                        "oneOf": [
                            {"type": "string"},
                            {
                                "oneOf": [
                                    {"type": "string"},
                                    {
                                        "properties": {
                                            "bar": {"type": "array"},
                                        },
                                    },
                                ],
                            },
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo": {"bar": 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 29
Project: TA-intezer   Author: secops4thewin   File: test_exceptions.py    MIT License 6 votes vote down vote up
def test_oneOf_and_anyOf_are_weak_matches(self):
        """
        A property you *must* match is probably better than one you have to
        match a part of.

        """

        validator = Draft4Validator(
            {
                "minProperties" : 2,
                "anyOf" : [{"type" : "string"}, {"type" : "number"}],
                "oneOf" : [{"type" : "string"}, {"type" : "number"}],
            }
        )
        best = self.best_match(validator.iter_errors({}))
        self.assertEqual(best.validator, "minProperties") 
Example 30
Project: TA-intezer   Author: secops4thewin   File: test_exceptions.py    MIT License 6 votes vote down vote up
def test_if_the_most_relevant_error_is_anyOf_it_is_traversed(self):
        """
        If the most relevant error is an anyOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "anyOf" : [
                            {"type" : "string"},
                            {"properties" : {"bar" : {"type" : "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 31
Project: TA-intezer   Author: secops4thewin   File: test_exceptions.py    MIT License 6 votes vote down vote up
def test_if_the_most_relevant_error_is_oneOf_it_is_traversed(self):
        """
        If the most relevant error is an oneOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "oneOf" : [
                            {"type" : "string"},
                            {"properties" : {"bar" : {"type" : "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 32
Project: TA-intezer   Author: secops4thewin   File: test_exceptions.py    MIT License 6 votes vote down vote up
def test_nested_context_for_oneOf(self):
        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "oneOf" : [
                            {"type" : "string"},
                            {
                                "oneOf" : [
                                    {"type" : "string"},
                                    {
                                        "properties" : {
                                            "bar" : {"type" : "array"}
                                        },
                                    },
                                ],
                            },
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
Example 33
Project: misp42splunk   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def best_match(self, errors):
        errors = list(errors)
        best = exceptions.best_match(errors)
        reversed_best = exceptions.best_match(reversed(errors))
        self.assertEqual(
            best,
            reversed_best,
            msg="Didn't return a consistent best match!\n"
                "Got: {0}\n\nThen: {1}".format(best, reversed_best),
        )
        return best 
Example 34
Project: misp42splunk   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_shallower_errors_are_better_matches(self):
        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "minProperties" : 2,
                        "properties" : {"bar" : {"type" : "object"}},
                    }
                }
            }
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : []}}))
        self.assertEqual(best.validator, "minProperties") 
Example 35
Project: misp42splunk   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_one_error(self):
        validator = Draft4Validator({"minProperties" : 2})
        error, = validator.iter_errors({})
        self.assertEqual(
            exceptions.best_match(validator.iter_errors({})).validator,
            "minProperties",
        ) 
Example 36
Project: misp42splunk   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_no_errors(self):
        validator = Draft4Validator({})
        self.assertIsNone(exceptions.best_match(validator.iter_errors({}))) 
Example 37
Project: misp42splunk   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_weak_validators_are_lower_priority(self):
        weak = exceptions.ValidationError("Oh no!", path=[], validator="a")
        normal = exceptions.ValidationError("Oh yes!", path=[], validator="b")

        best_match = exceptions.by_relevance(weak="a")

        match = max([weak, normal], key=best_match)
        self.assertIs(match, normal)

        match = max([normal, weak], key=best_match)
        self.assertIs(match, normal) 
Example 38
Project: misp42splunk   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_strong_validators_are_higher_priority(self):
        weak = exceptions.ValidationError("Oh no!", path=[], validator="a")
        normal = exceptions.ValidationError("Oh yes!", path=[], validator="b")
        strong = exceptions.ValidationError("Oh fine!", path=[], validator="c")

        best_match = exceptions.by_relevance(weak="a", strong="c")

        match = max([weak, normal, strong], key=best_match)
        self.assertIs(match, strong)

        match = max([strong, normal, weak], key=best_match)
        self.assertIs(match, strong) 
Example 39
Project: core   Author: getavalon   File: test_exceptions.py    MIT License 5 votes vote down vote up
def best_match(self, errors):
        errors = list(errors)
        best = exceptions.best_match(errors)
        reversed_best = exceptions.best_match(reversed(errors))
        self.assertEqual(
            best,
            reversed_best,
            msg="Didn't return a consistent best match!\n"
                "Got: {0}\n\nThen: {1}".format(best, reversed_best),
        )
        return best 
Example 40
Project: core   Author: getavalon   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_shallower_errors_are_better_matches(self):
        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "minProperties" : 2,
                        "properties" : {"bar" : {"type" : "object"}},
                    }
                }
            }
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : []}}))
        self.assertEqual(best.validator, "minProperties") 
Example 41
Project: core   Author: getavalon   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_one_error(self):
        validator = Draft4Validator({"minProperties" : 2})
        error, = validator.iter_errors({})
        self.assertEqual(
            exceptions.best_match(validator.iter_errors({})).validator,
            "minProperties",
        ) 
Example 42
Project: core   Author: getavalon   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_no_errors(self):
        validator = Draft4Validator({})
        self.assertIsNone(exceptions.best_match(validator.iter_errors({}))) 
Example 43
Project: core   Author: getavalon   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_weak_validators_are_lower_priority(self):
        weak = exceptions.ValidationError("Oh no!", path=[], validator="a")
        normal = exceptions.ValidationError("Oh yes!", path=[], validator="b")

        best_match = exceptions.by_relevance(weak="a")

        match = max([weak, normal], key=best_match)
        self.assertIs(match, normal)

        match = max([normal, weak], key=best_match)
        self.assertIs(match, normal) 
Example 44
Project: core   Author: getavalon   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_strong_validators_are_higher_priority(self):
        weak = exceptions.ValidationError("Oh no!", path=[], validator="a")
        normal = exceptions.ValidationError("Oh yes!", path=[], validator="b")
        strong = exceptions.ValidationError("Oh fine!", path=[], validator="c")

        best_match = exceptions.by_relevance(weak="a", strong="c")

        match = max([weak, normal, strong], key=best_match)
        self.assertIs(match, strong)

        match = max([strong, normal, weak], key=best_match)
        self.assertIs(match, strong) 
Example 45
Project: git_for_splunk   Author: ChrisYounger   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def best_match(self, errors):
        errors = list(errors)
        best = exceptions.best_match(errors)
        reversed_best = exceptions.best_match(reversed(errors))
        self.assertEqual(
            best,
            reversed_best,
            msg="Didn't return a consistent best match!\n"
                "Got: {0}\n\nThen: {1}".format(best, reversed_best),
        )
        return best 
Example 46
Project: git_for_splunk   Author: ChrisYounger   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_shallower_errors_are_better_matches(self):
        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "minProperties" : 2,
                        "properties" : {"bar" : {"type" : "object"}},
                    }
                }
            }
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : []}}))
        self.assertEqual(best.validator, "minProperties") 
Example 47
Project: git_for_splunk   Author: ChrisYounger   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_one_error(self):
        validator = Draft4Validator({"minProperties" : 2})
        error, = validator.iter_errors({})
        self.assertEqual(
            exceptions.best_match(validator.iter_errors({})).validator,
            "minProperties",
        ) 
Example 48
Project: git_for_splunk   Author: ChrisYounger   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_no_errors(self):
        validator = Draft4Validator({})
        self.assertIsNone(exceptions.best_match(validator.iter_errors({}))) 
Example 49
Project: git_for_splunk   Author: ChrisYounger   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_weak_validators_are_lower_priority(self):
        weak = exceptions.ValidationError("Oh no!", path=[], validator="a")
        normal = exceptions.ValidationError("Oh yes!", path=[], validator="b")

        best_match = exceptions.by_relevance(weak="a")

        match = max([weak, normal], key=best_match)
        self.assertIs(match, normal)

        match = max([normal, weak], key=best_match)
        self.assertIs(match, normal) 
Example 50
Project: git_for_splunk   Author: ChrisYounger   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_strong_validators_are_higher_priority(self):
        weak = exceptions.ValidationError("Oh no!", path=[], validator="a")
        normal = exceptions.ValidationError("Oh yes!", path=[], validator="b")
        strong = exceptions.ValidationError("Oh fine!", path=[], validator="c")

        best_match = exceptions.by_relevance(weak="a", strong="c")

        match = max([weak, normal, strong], key=best_match)
        self.assertIs(match, strong)

        match = max([strong, normal, weak], key=best_match)
        self.assertIs(match, strong) 
Example 51
Project: pyblish-rpc   Author: pyblish   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def best_match(self, errors):
        errors = list(errors)
        best = exceptions.best_match(errors)
        reversed_best = exceptions.best_match(reversed(errors))
        self.assertEqual(
            best,
            reversed_best,
            msg="Didn't return a consistent best match!\n"
                "Got: {0}\n\nThen: {1}".format(best, reversed_best),
        )
        return best 
Example 52
Project: pyblish-rpc   Author: pyblish   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_shallower_errors_are_better_matches(self):
        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "minProperties" : 2,
                        "properties" : {"bar" : {"type" : "object"}},
                    }
                }
            }
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : []}}))
        self.assertEqual(best.validator, "minProperties") 
Example 53
Project: pyblish-rpc   Author: pyblish   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_one_error(self):
        validator = Draft4Validator({"minProperties" : 2})
        error, = validator.iter_errors({})
        self.assertEqual(
            exceptions.best_match(validator.iter_errors({})).validator,
            "minProperties",
        ) 
Example 54
Project: pyblish-rpc   Author: pyblish   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_no_errors(self):
        validator = Draft4Validator({})
        self.assertIsNone(exceptions.best_match(validator.iter_errors({}))) 
Example 55
Project: pyblish-rpc   Author: pyblish   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_weak_validators_are_lower_priority(self):
        weak = exceptions.ValidationError("Oh no!", path=[], validator="a")
        normal = exceptions.ValidationError("Oh yes!", path=[], validator="b")

        best_match = exceptions.by_relevance(weak="a")

        match = max([weak, normal], key=best_match)
        self.assertIs(match, normal)

        match = max([normal, weak], key=best_match)
        self.assertIs(match, normal) 
Example 56
Project: pyblish-rpc   Author: pyblish   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_strong_validators_are_higher_priority(self):
        weak = exceptions.ValidationError("Oh no!", path=[], validator="a")
        normal = exceptions.ValidationError("Oh yes!", path=[], validator="b")
        strong = exceptions.ValidationError("Oh fine!", path=[], validator="c")

        best_match = exceptions.by_relevance(weak="a", strong="c")

        match = max([weak, normal, strong], key=best_match)
        self.assertIs(match, strong)

        match = max([strong, normal, weak], key=best_match)
        self.assertIs(match, strong) 
Example 57
Project: paasta   Author: Yelp   File: validate.py    Apache License 2.0 5 votes vote down vote up
def validate_schema(file_path, file_type):
    """Check if the specified config file has a valid schema

    :param file_path: path to file to validate
    :param file_type: what schema type should we validate against
    """
    try:
        schema = get_schema(file_type)
    except Exception as e:
        paasta_print(f"{SCHEMA_ERROR}: {file_type}, error: {e!r}")
        return

    if schema is None:
        paasta_print(f"{SCHEMA_NOT_FOUND}: {file_path}")
        return
    validator = Draft4Validator(schema, format_checker=FormatChecker())
    basename = os.path.basename(file_path)
    config_file_object = get_config_file_dict(file_path)
    try:
        validator.validate(config_file_object)
        if file_type == "kubernetes" and not validate_instance_names(
            config_file_object, file_path
        ):
            return
    except ValidationError:
        paasta_print(f"{SCHEMA_INVALID}: {file_path}")

        errors = validator.iter_errors(config_file_object)
        paasta_print("  Validation Message: %s" % exceptions.best_match(errors).message)
    except Exception as e:
        paasta_print(f"{SCHEMA_ERROR}: {file_type}, error: {e!r}")
        return
    else:
        paasta_print(f"{SCHEMA_VALID}: {basename}")
        return True 
Example 58
Project: pastebin2misp   Author: renzejongman   File: test_exceptions.py    MIT License 5 votes vote down vote up
def best_match(self, errors):
        errors = list(errors)
        best = exceptions.best_match(errors)
        reversed_best = exceptions.best_match(reversed(errors))
        msg = "Didn't return a consistent best match!\nGot: {0}\n\nThen: {1}"
        self.assertEqual(
            best, reversed_best, msg=msg.format(best, reversed_best),
        )
        return best 
Example 59
Project: pastebin2misp   Author: renzejongman   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_shallower_errors_are_better_matches(self):
        validator = Draft4Validator(
            {
                "properties": {
                    "foo": {
                        "minProperties": 2,
                        "properties": {"bar": {"type": "object"}},
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo": {"bar": []}}))
        self.assertEqual(best.validator, "minProperties") 
Example 60
Project: pastebin2misp   Author: renzejongman   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_one_error(self):
        validator = Draft4Validator({"minProperties": 2})
        error, = validator.iter_errors({})
        self.assertEqual(
            exceptions.best_match(validator.iter_errors({})).validator,
            "minProperties",
        ) 
Example 61
Project: pastebin2misp   Author: renzejongman   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_no_errors(self):
        validator = Draft4Validator({})
        self.assertIsNone(exceptions.best_match(validator.iter_errors({}))) 
Example 62
Project: pastebin2misp   Author: renzejongman   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_weak_validators_are_lower_priority(self):
        weak = exceptions.ValidationError("Oh no!", path=[], validator="a")
        normal = exceptions.ValidationError("Oh yes!", path=[], validator="b")

        best_match = exceptions.by_relevance(weak="a")

        match = max([weak, normal], key=best_match)
        self.assertIs(match, normal)

        match = max([normal, weak], key=best_match)
        self.assertIs(match, normal) 
Example 63
Project: pastebin2misp   Author: renzejongman   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_strong_validators_are_higher_priority(self):
        weak = exceptions.ValidationError("Oh no!", path=[], validator="a")
        normal = exceptions.ValidationError("Oh yes!", path=[], validator="b")
        strong = exceptions.ValidationError("Oh fine!", path=[], validator="c")

        best_match = exceptions.by_relevance(weak="a", strong="c")

        match = max([weak, normal, strong], key=best_match)
        self.assertIs(match, strong)

        match = max([strong, normal, weak], key=best_match)
        self.assertIs(match, strong) 
Example 64
Project: TA-thehive   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def best_match(self, errors):
        errors = list(errors)
        best = exceptions.best_match(errors)
        reversed_best = exceptions.best_match(reversed(errors))
        self.assertEqual(
            best,
            reversed_best,
            msg="Didn't return a consistent best match!\n"
                "Got: {0}\n\nThen: {1}".format(best, reversed_best),
        )
        return best 
Example 65
Project: TA-thehive   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_shallower_errors_are_better_matches(self):
        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "minProperties" : 2,
                        "properties" : {"bar" : {"type" : "object"}},
                    }
                }
            }
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : []}}))
        self.assertEqual(best.validator, "minProperties") 
Example 66
Project: TA-thehive   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_one_error(self):
        validator = Draft4Validator({"minProperties" : 2})
        error, = validator.iter_errors({})
        self.assertEqual(
            exceptions.best_match(validator.iter_errors({})).validator,
            "minProperties",
        ) 
Example 67
Project: TA-thehive   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_no_errors(self):
        validator = Draft4Validator({})
        self.assertIsNone(exceptions.best_match(validator.iter_errors({}))) 
Example 68
Project: TA-thehive   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_weak_validators_are_lower_priority(self):
        weak = exceptions.ValidationError("Oh no!", path=[], validator="a")
        normal = exceptions.ValidationError("Oh yes!", path=[], validator="b")

        best_match = exceptions.by_relevance(weak="a")

        match = max([weak, normal], key=best_match)
        self.assertIs(match, normal)

        match = max([normal, weak], key=best_match)
        self.assertIs(match, normal) 
Example 69
Project: TA-thehive   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_strong_validators_are_higher_priority(self):
        weak = exceptions.ValidationError("Oh no!", path=[], validator="a")
        normal = exceptions.ValidationError("Oh yes!", path=[], validator="b")
        strong = exceptions.ValidationError("Oh fine!", path=[], validator="c")

        best_match = exceptions.by_relevance(weak="a", strong="c")

        match = max([weak, normal, strong], key=best_match)
        self.assertIs(match, strong)

        match = max([strong, normal, weak], key=best_match)
        self.assertIs(match, strong) 
Example 70
Project: accelerated-data-lake   Author: aws-samples   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def best_match(self, errors):
        errors = list(errors)
        best = exceptions.best_match(errors)
        reversed_best = exceptions.best_match(reversed(errors))
        msg = "Didn't return a consistent best match!\nGot: {0}\n\nThen: {1}"
        self.assertEqual(
            best, reversed_best, msg=msg.format(best, reversed_best),
        )
        return best 
Example 71
Project: accelerated-data-lake   Author: aws-samples   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_shallower_errors_are_better_matches(self):
        validator = Draft4Validator(
            {
                "properties": {
                    "foo": {
                        "minProperties": 2,
                        "properties": {"bar": {"type": "object"}},
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo": {"bar": []}}))
        self.assertEqual(best.validator, "minProperties") 
Example 72
Project: accelerated-data-lake   Author: aws-samples   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_one_error(self):
        validator = Draft4Validator({"minProperties": 2})
        error, = validator.iter_errors({})
        self.assertEqual(
            exceptions.best_match(validator.iter_errors({})).validator,
            "minProperties",
        ) 
Example 73
Project: accelerated-data-lake   Author: aws-samples   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_no_errors(self):
        validator = Draft4Validator({})
        self.assertIsNone(exceptions.best_match(validator.iter_errors({}))) 
Example 74
Project: accelerated-data-lake   Author: aws-samples   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_weak_validators_are_lower_priority(self):
        weak = exceptions.ValidationError("Oh no!", path=[], validator="a")
        normal = exceptions.ValidationError("Oh yes!", path=[], validator="b")

        best_match = exceptions.by_relevance(weak="a")

        match = max([weak, normal], key=best_match)
        self.assertIs(match, normal)

        match = max([normal, weak], key=best_match)
        self.assertIs(match, normal) 
Example 75
Project: accelerated-data-lake   Author: aws-samples   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_strong_validators_are_higher_priority(self):
        weak = exceptions.ValidationError("Oh no!", path=[], validator="a")
        normal = exceptions.ValidationError("Oh yes!", path=[], validator="b")
        strong = exceptions.ValidationError("Oh fine!", path=[], validator="c")

        best_match = exceptions.by_relevance(weak="a", strong="c")

        match = max([weak, normal, strong], key=best_match)
        self.assertIs(match, strong)

        match = max([strong, normal, weak], key=best_match)
        self.assertIs(match, strong) 
Example 76
Project: TA-intezer   Author: secops4thewin   File: test_exceptions.py    MIT License 5 votes vote down vote up
def best_match(self, errors):
        errors = list(errors)
        best = exceptions.best_match(errors)
        reversed_best = exceptions.best_match(reversed(errors))
        self.assertEqual(
            best,
            reversed_best,
            msg="Didn't return a consistent best match!\n"
                "Got: {0}\n\nThen: {1}".format(best, reversed_best),
        )
        return best 
Example 77
Project: TA-intezer   Author: secops4thewin   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_shallower_errors_are_better_matches(self):
        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "minProperties" : 2,
                        "properties" : {"bar" : {"type" : "object"}},
                    }
                }
            }
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : []}}))
        self.assertEqual(best.validator, "minProperties") 
Example 78
Project: TA-intezer   Author: secops4thewin   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_one_error(self):
        validator = Draft4Validator({"minProperties" : 2})
        error, = validator.iter_errors({})
        self.assertEqual(
            exceptions.best_match(validator.iter_errors({})).validator,
            "minProperties",
        ) 
Example 79
Project: TA-intezer   Author: secops4thewin   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_no_errors(self):
        validator = Draft4Validator({})
        self.assertIsNone(exceptions.best_match(validator.iter_errors({}))) 
Example 80
Project: TA-intezer   Author: secops4thewin   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_weak_validators_are_lower_priority(self):
        weak = exceptions.ValidationError("Oh no!", path=[], validator="a")
        normal = exceptions.ValidationError("Oh yes!", path=[], validator="b")

        best_match = exceptions.by_relevance(weak="a")

        match = max([weak, normal], key=best_match)
        self.assertIs(match, normal)

        match = max([normal, weak], key=best_match)
        self.assertIs(match, normal)