Python jsonschema.exceptions.ErrorTree() Examples

The following are code examples for showing how to use jsonschema.exceptions.ErrorTree(). 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 5 votes vote down vote up
def test_it_knows_how_many_total_errors_it_contains(self):
        errors = [mock.MagicMock() for _ in range(8)]
        tree = exceptions.ErrorTree(errors)
        self.assertEqual(tree.total_errors, 8) 
Example 2
Project: misp42splunk   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_it_contains_an_item_if_the_item_had_an_error(self):
        errors = [exceptions.ValidationError("a message", path=["bar"])]
        tree = exceptions.ErrorTree(errors)
        self.assertIn("bar", tree) 
Example 3
Project: misp42splunk   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_it_does_not_contain_an_item_if_the_item_had_no_error(self):
        errors = [exceptions.ValidationError("a message", path=["bar"])]
        tree = exceptions.ErrorTree(errors)
        self.assertNotIn("foo", tree) 
Example 4
Project: misp42splunk   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_validators_that_failed_appear_in_errors_dict(self):
        error = exceptions.ValidationError("a message", validator="foo")
        tree = exceptions.ErrorTree([error])
        self.assertEqual(tree.errors, {"foo" : error}) 
Example 5
Project: misp42splunk   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_it_creates_a_child_tree_for_each_nested_path(self):
        errors = [
            exceptions.ValidationError("a bar message", path=["bar"]),
            exceptions.ValidationError("a bar -> 0 message", path=["bar", 0]),
        ]
        tree = exceptions.ErrorTree(errors)
        self.assertIn(0, tree["bar"])
        self.assertNotIn(1, tree["bar"]) 
Example 6
Project: misp42splunk   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_it_does_not_contain_subtrees_that_are_not_in_the_instance(self):
        error = exceptions.ValidationError("123", validator="foo", instance=[])
        tree = exceptions.ErrorTree([error])

        with self.assertRaises(IndexError):
            tree[0] 
Example 7
Project: misp42splunk   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_if_its_in_the_tree_anyhow_it_does_not_raise_an_error(self):
        """
        If a validator is dumb (like :validator:`required` in draft 3) and
        refers to a path that isn't in the instance, the tree still properly
        returns a subtree for that path.

        """

        error = exceptions.ValidationError(
            "a message", validator="foo", instance={}, path=["foo"],
        )
        tree = exceptions.ErrorTree([error])
        self.assertIsInstance(tree["foo"], exceptions.ErrorTree) 
Example 8
Project: core   Author: getavalon   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_knows_how_many_total_errors_it_contains(self):
        errors = [mock.MagicMock() for _ in range(8)]
        tree = exceptions.ErrorTree(errors)
        self.assertEqual(tree.total_errors, 8) 
Example 9
Project: core   Author: getavalon   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_contains_an_item_if_the_item_had_an_error(self):
        errors = [exceptions.ValidationError("a message", path=["bar"])]
        tree = exceptions.ErrorTree(errors)
        self.assertIn("bar", tree) 
Example 10
Project: core   Author: getavalon   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_does_not_contain_an_item_if_the_item_had_no_error(self):
        errors = [exceptions.ValidationError("a message", path=["bar"])]
        tree = exceptions.ErrorTree(errors)
        self.assertNotIn("foo", tree) 
Example 11
Project: core   Author: getavalon   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_validators_that_failed_appear_in_errors_dict(self):
        error = exceptions.ValidationError("a message", validator="foo")
        tree = exceptions.ErrorTree([error])
        self.assertEqual(tree.errors, {"foo" : error}) 
Example 12
Project: core   Author: getavalon   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_creates_a_child_tree_for_each_nested_path(self):
        errors = [
            exceptions.ValidationError("a bar message", path=["bar"]),
            exceptions.ValidationError("a bar -> 0 message", path=["bar", 0]),
        ]
        tree = exceptions.ErrorTree(errors)
        self.assertIn(0, tree["bar"])
        self.assertNotIn(1, tree["bar"]) 
Example 13
Project: core   Author: getavalon   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_does_not_contain_subtrees_that_are_not_in_the_instance(self):
        error = exceptions.ValidationError("123", validator="foo", instance=[])
        tree = exceptions.ErrorTree([error])

        with self.assertRaises(IndexError):
            tree[0] 
Example 14
Project: core   Author: getavalon   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_if_its_in_the_tree_anyhow_it_does_not_raise_an_error(self):
        """
        If a validator is dumb (like :validator:`required` in draft 3) and
        refers to a path that isn't in the instance, the tree still properly
        returns a subtree for that path.

        """

        error = exceptions.ValidationError(
            "a message", validator="foo", instance={}, path=["foo"],
        )
        tree = exceptions.ErrorTree([error])
        self.assertIsInstance(tree["foo"], exceptions.ErrorTree) 
Example 15
Project: git_for_splunk   Author: ChrisYounger   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_it_knows_how_many_total_errors_it_contains(self):
        errors = [mock.MagicMock() for _ in range(8)]
        tree = exceptions.ErrorTree(errors)
        self.assertEqual(tree.total_errors, 8) 
Example 16
Project: git_for_splunk   Author: ChrisYounger   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_it_contains_an_item_if_the_item_had_an_error(self):
        errors = [exceptions.ValidationError("a message", path=["bar"])]
        tree = exceptions.ErrorTree(errors)
        self.assertIn("bar", tree) 
Example 17
Project: git_for_splunk   Author: ChrisYounger   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_it_does_not_contain_an_item_if_the_item_had_no_error(self):
        errors = [exceptions.ValidationError("a message", path=["bar"])]
        tree = exceptions.ErrorTree(errors)
        self.assertNotIn("foo", tree) 
Example 18
Project: git_for_splunk   Author: ChrisYounger   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_validators_that_failed_appear_in_errors_dict(self):
        error = exceptions.ValidationError("a message", validator="foo")
        tree = exceptions.ErrorTree([error])
        self.assertEqual(tree.errors, {"foo" : error}) 
Example 19
Project: git_for_splunk   Author: ChrisYounger   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_it_creates_a_child_tree_for_each_nested_path(self):
        errors = [
            exceptions.ValidationError("a bar message", path=["bar"]),
            exceptions.ValidationError("a bar -> 0 message", path=["bar", 0]),
        ]
        tree = exceptions.ErrorTree(errors)
        self.assertIn(0, tree["bar"])
        self.assertNotIn(1, tree["bar"]) 
Example 20
Project: git_for_splunk   Author: ChrisYounger   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_it_does_not_contain_subtrees_that_are_not_in_the_instance(self):
        error = exceptions.ValidationError("123", validator="foo", instance=[])
        tree = exceptions.ErrorTree([error])

        with self.assertRaises(IndexError):
            tree[0] 
Example 21
Project: git_for_splunk   Author: ChrisYounger   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_if_its_in_the_tree_anyhow_it_does_not_raise_an_error(self):
        """
        If a validator is dumb (like :validator:`required` in draft 3) and
        refers to a path that isn't in the instance, the tree still properly
        returns a subtree for that path.

        """

        error = exceptions.ValidationError(
            "a message", validator="foo", instance={}, path=["foo"],
        )
        tree = exceptions.ErrorTree([error])
        self.assertIsInstance(tree["foo"], exceptions.ErrorTree) 
Example 22
Project: pyblish-rpc   Author: pyblish   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_it_knows_how_many_total_errors_it_contains(self):
        errors = [mock.MagicMock() for _ in range(8)]
        tree = exceptions.ErrorTree(errors)
        self.assertEqual(tree.total_errors, 8) 
Example 23
Project: pyblish-rpc   Author: pyblish   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_it_contains_an_item_if_the_item_had_an_error(self):
        errors = [exceptions.ValidationError("a message", path=["bar"])]
        tree = exceptions.ErrorTree(errors)
        self.assertIn("bar", tree) 
Example 24
Project: pyblish-rpc   Author: pyblish   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_it_does_not_contain_an_item_if_the_item_had_no_error(self):
        errors = [exceptions.ValidationError("a message", path=["bar"])]
        tree = exceptions.ErrorTree(errors)
        self.assertNotIn("foo", tree) 
Example 25
Project: pyblish-rpc   Author: pyblish   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_validators_that_failed_appear_in_errors_dict(self):
        error = exceptions.ValidationError("a message", validator="foo")
        tree = exceptions.ErrorTree([error])
        self.assertEqual(tree.errors, {"foo" : error}) 
Example 26
Project: pyblish-rpc   Author: pyblish   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_it_creates_a_child_tree_for_each_nested_path(self):
        errors = [
            exceptions.ValidationError("a bar message", path=["bar"]),
            exceptions.ValidationError("a bar -> 0 message", path=["bar", 0]),
        ]
        tree = exceptions.ErrorTree(errors)
        self.assertIn(0, tree["bar"])
        self.assertNotIn(1, tree["bar"]) 
Example 27
Project: pyblish-rpc   Author: pyblish   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_it_does_not_contain_subtrees_that_are_not_in_the_instance(self):
        error = exceptions.ValidationError("123", validator="foo", instance=[])
        tree = exceptions.ErrorTree([error])

        with self.assertRaises(IndexError):
            tree[0] 
Example 28
Project: pyblish-rpc   Author: pyblish   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_if_its_in_the_tree_anyhow_it_does_not_raise_an_error(self):
        """
        If a validator is dumb (like :validator:`required` in draft 3) and
        refers to a path that isn't in the instance, the tree still properly
        returns a subtree for that path.

        """

        error = exceptions.ValidationError(
            "a message", validator="foo", instance={}, path=["foo"],
        )
        tree = exceptions.ErrorTree([error])
        self.assertIsInstance(tree["foo"], exceptions.ErrorTree) 
Example 29
Project: pastebin2misp   Author: renzejongman   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_knows_how_many_total_errors_it_contains(self):
        errors = [mock.MagicMock() for _ in range(8)]
        tree = exceptions.ErrorTree(errors)
        self.assertEqual(tree.total_errors, 8) 
Example 30
Project: pastebin2misp   Author: renzejongman   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_contains_an_item_if_the_item_had_an_error(self):
        errors = [exceptions.ValidationError("a message", path=["bar"])]
        tree = exceptions.ErrorTree(errors)
        self.assertIn("bar", tree) 
Example 31
Project: pastebin2misp   Author: renzejongman   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_does_not_contain_an_item_if_the_item_had_no_error(self):
        errors = [exceptions.ValidationError("a message", path=["bar"])]
        tree = exceptions.ErrorTree(errors)
        self.assertNotIn("foo", tree) 
Example 32
Project: pastebin2misp   Author: renzejongman   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_validators_that_failed_appear_in_errors_dict(self):
        error = exceptions.ValidationError("a message", validator="foo")
        tree = exceptions.ErrorTree([error])
        self.assertEqual(tree.errors, {"foo": error}) 
Example 33
Project: pastebin2misp   Author: renzejongman   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_creates_a_child_tree_for_each_nested_path(self):
        errors = [
            exceptions.ValidationError("a bar message", path=["bar"]),
            exceptions.ValidationError("a bar -> 0 message", path=["bar", 0]),
        ]
        tree = exceptions.ErrorTree(errors)
        self.assertIn(0, tree["bar"])
        self.assertNotIn(1, tree["bar"]) 
Example 34
Project: pastebin2misp   Author: renzejongman   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_regression_multiple_errors_with_instance(self):
        e1, e2 = (
            exceptions.ValidationError(
                "1",
                validator="foo",
                path=["bar", "bar2"],
                instance="i1"),
            exceptions.ValidationError(
                "2",
                validator="quux",
                path=["foobar", 2],
                instance="i2"),
        )
        # Will raise an exception if the bug is still there.
        exceptions.ErrorTree([e1, e2]) 
Example 35
Project: pastebin2misp   Author: renzejongman   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_does_not_contain_subtrees_that_are_not_in_the_instance(self):
        error = exceptions.ValidationError("123", validator="foo", instance=[])
        tree = exceptions.ErrorTree([error])

        with self.assertRaises(IndexError):
            tree[0] 
Example 36
Project: pastebin2misp   Author: renzejongman   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_if_its_in_the_tree_anyhow_it_does_not_raise_an_error(self):
        """
        If a validator is dumb (like :validator:`required` in draft 3) and
        refers to a path that isn't in the instance, the tree still properly
        returns a subtree for that path.

        """

        error = exceptions.ValidationError(
            "a message", validator="foo", instance={}, path=["foo"],
        )
        tree = exceptions.ErrorTree([error])
        self.assertIsInstance(tree["foo"], exceptions.ErrorTree) 
Example 37
Project: TA-thehive   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_it_knows_how_many_total_errors_it_contains(self):
        errors = [mock.MagicMock() for _ in range(8)]
        tree = exceptions.ErrorTree(errors)
        self.assertEqual(tree.total_errors, 8) 
Example 38
Project: TA-thehive   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_it_contains_an_item_if_the_item_had_an_error(self):
        errors = [exceptions.ValidationError("a message", path=["bar"])]
        tree = exceptions.ErrorTree(errors)
        self.assertIn("bar", tree) 
Example 39
Project: TA-thehive   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_it_does_not_contain_an_item_if_the_item_had_no_error(self):
        errors = [exceptions.ValidationError("a message", path=["bar"])]
        tree = exceptions.ErrorTree(errors)
        self.assertNotIn("foo", tree) 
Example 40
Project: TA-thehive   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_validators_that_failed_appear_in_errors_dict(self):
        error = exceptions.ValidationError("a message", validator="foo")
        tree = exceptions.ErrorTree([error])
        self.assertEqual(tree.errors, {"foo" : error}) 
Example 41
Project: TA-thehive   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_it_creates_a_child_tree_for_each_nested_path(self):
        errors = [
            exceptions.ValidationError("a bar message", path=["bar"]),
            exceptions.ValidationError("a bar -> 0 message", path=["bar", 0]),
        ]
        tree = exceptions.ErrorTree(errors)
        self.assertIn(0, tree["bar"])
        self.assertNotIn(1, tree["bar"]) 
Example 42
Project: TA-thehive   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_it_does_not_contain_subtrees_that_are_not_in_the_instance(self):
        error = exceptions.ValidationError("123", validator="foo", instance=[])
        tree = exceptions.ErrorTree([error])

        with self.assertRaises(IndexError):
            tree[0] 
Example 43
Project: TA-thehive   Author: remg427   File: test_exceptions.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_if_its_in_the_tree_anyhow_it_does_not_raise_an_error(self):
        """
        If a validator is dumb (like :validator:`required` in draft 3) and
        refers to a path that isn't in the instance, the tree still properly
        returns a subtree for that path.

        """

        error = exceptions.ValidationError(
            "a message", validator="foo", instance={}, path=["foo"],
        )
        tree = exceptions.ErrorTree([error])
        self.assertIsInstance(tree["foo"], exceptions.ErrorTree) 
Example 44
Project: accelerated-data-lake   Author: aws-samples   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_it_knows_how_many_total_errors_it_contains(self):
        errors = [mock.MagicMock() for _ in range(8)]
        tree = exceptions.ErrorTree(errors)
        self.assertEqual(tree.total_errors, 8) 
Example 45
Project: accelerated-data-lake   Author: aws-samples   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_it_contains_an_item_if_the_item_had_an_error(self):
        errors = [exceptions.ValidationError("a message", path=["bar"])]
        tree = exceptions.ErrorTree(errors)
        self.assertIn("bar", tree) 
Example 46
Project: accelerated-data-lake   Author: aws-samples   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_it_does_not_contain_an_item_if_the_item_had_no_error(self):
        errors = [exceptions.ValidationError("a message", path=["bar"])]
        tree = exceptions.ErrorTree(errors)
        self.assertNotIn("foo", tree) 
Example 47
Project: accelerated-data-lake   Author: aws-samples   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_validators_that_failed_appear_in_errors_dict(self):
        error = exceptions.ValidationError("a message", validator="foo")
        tree = exceptions.ErrorTree([error])
        self.assertEqual(tree.errors, {"foo": error}) 
Example 48
Project: accelerated-data-lake   Author: aws-samples   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_it_creates_a_child_tree_for_each_nested_path(self):
        errors = [
            exceptions.ValidationError("a bar message", path=["bar"]),
            exceptions.ValidationError("a bar -> 0 message", path=["bar", 0]),
        ]
        tree = exceptions.ErrorTree(errors)
        self.assertIn(0, tree["bar"])
        self.assertNotIn(1, tree["bar"]) 
Example 49
Project: accelerated-data-lake   Author: aws-samples   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_regression_multiple_errors_with_instance(self):
        e1, e2 = (
            exceptions.ValidationError(
                "1",
                validator="foo",
                path=["bar", "bar2"],
                instance="i1"),
            exceptions.ValidationError(
                "2",
                validator="quux",
                path=["foobar", 2],
                instance="i2"),
        )
        # Will raise an exception if the bug is still there.
        exceptions.ErrorTree([e1, e2]) 
Example 50
Project: accelerated-data-lake   Author: aws-samples   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_it_does_not_contain_subtrees_that_are_not_in_the_instance(self):
        error = exceptions.ValidationError("123", validator="foo", instance=[])
        tree = exceptions.ErrorTree([error])

        with self.assertRaises(IndexError):
            tree[0] 
Example 51
Project: accelerated-data-lake   Author: aws-samples   File: test_exceptions.py    Apache License 2.0 5 votes vote down vote up
def test_if_its_in_the_tree_anyhow_it_does_not_raise_an_error(self):
        """
        If a validator is dumb (like :validator:`required` in draft 3) and
        refers to a path that isn't in the instance, the tree still properly
        returns a subtree for that path.

        """

        error = exceptions.ValidationError(
            "a message", validator="foo", instance={}, path=["foo"],
        )
        tree = exceptions.ErrorTree([error])
        self.assertIsInstance(tree["foo"], exceptions.ErrorTree) 
Example 52
Project: TA-intezer   Author: secops4thewin   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_knows_how_many_total_errors_it_contains(self):
        errors = [mock.MagicMock() for _ in range(8)]
        tree = exceptions.ErrorTree(errors)
        self.assertEqual(tree.total_errors, 8) 
Example 53
Project: TA-intezer   Author: secops4thewin   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_contains_an_item_if_the_item_had_an_error(self):
        errors = [exceptions.ValidationError("a message", path=["bar"])]
        tree = exceptions.ErrorTree(errors)
        self.assertIn("bar", tree) 
Example 54
Project: TA-intezer   Author: secops4thewin   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_does_not_contain_an_item_if_the_item_had_no_error(self):
        errors = [exceptions.ValidationError("a message", path=["bar"])]
        tree = exceptions.ErrorTree(errors)
        self.assertNotIn("foo", tree) 
Example 55
Project: TA-intezer   Author: secops4thewin   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_validators_that_failed_appear_in_errors_dict(self):
        error = exceptions.ValidationError("a message", validator="foo")
        tree = exceptions.ErrorTree([error])
        self.assertEqual(tree.errors, {"foo" : error}) 
Example 56
Project: TA-intezer   Author: secops4thewin   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_creates_a_child_tree_for_each_nested_path(self):
        errors = [
            exceptions.ValidationError("a bar message", path=["bar"]),
            exceptions.ValidationError("a bar -> 0 message", path=["bar", 0]),
        ]
        tree = exceptions.ErrorTree(errors)
        self.assertIn(0, tree["bar"])
        self.assertNotIn(1, tree["bar"]) 
Example 57
Project: TA-intezer   Author: secops4thewin   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_does_not_contain_subtrees_that_are_not_in_the_instance(self):
        error = exceptions.ValidationError("123", validator="foo", instance=[])
        tree = exceptions.ErrorTree([error])

        with self.assertRaises(IndexError):
            tree[0] 
Example 58
Project: TA-intezer   Author: secops4thewin   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_if_its_in_the_tree_anyhow_it_does_not_raise_an_error(self):
        """
        If a validator is dumb (like :validator:`required` in draft 3) and
        refers to a path that isn't in the instance, the tree still properly
        returns a subtree for that path.

        """

        error = exceptions.ValidationError(
            "a message", validator="foo", instance={}, path=["foo"],
        )
        tree = exceptions.ErrorTree([error])
        self.assertIsInstance(tree["foo"], exceptions.ErrorTree) 
Example 59
Project: Requester   Author: kylebebak   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_knows_how_many_total_errors_it_contains(self):
        errors = [mock.MagicMock() for _ in range(8)]
        tree = exceptions.ErrorTree(errors)
        self.assertEqual(tree.total_errors, 8) 
Example 60
Project: Requester   Author: kylebebak   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_contains_an_item_if_the_item_had_an_error(self):
        errors = [exceptions.ValidationError("a message", path=["bar"])]
        tree = exceptions.ErrorTree(errors)
        self.assertIn("bar", tree) 
Example 61
Project: Requester   Author: kylebebak   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_does_not_contain_an_item_if_the_item_had_no_error(self):
        errors = [exceptions.ValidationError("a message", path=["bar"])]
        tree = exceptions.ErrorTree(errors)
        self.assertNotIn("foo", tree) 
Example 62
Project: Requester   Author: kylebebak   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_validators_that_failed_appear_in_errors_dict(self):
        error = exceptions.ValidationError("a message", validator="foo")
        tree = exceptions.ErrorTree([error])
        self.assertEqual(tree.errors, {"foo": error}) 
Example 63
Project: Requester   Author: kylebebak   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_creates_a_child_tree_for_each_nested_path(self):
        errors = [
            exceptions.ValidationError("a bar message", path=["bar"]),
            exceptions.ValidationError("a bar -> 0 message", path=["bar", 0]),
        ]
        tree = exceptions.ErrorTree(errors)
        self.assertIn(0, tree["bar"])
        self.assertNotIn(1, tree["bar"]) 
Example 64
Project: Requester   Author: kylebebak   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_regression_multiple_errors_with_instance(self):
        e1, e2 = (
            exceptions.ValidationError(
                "1",
                validator="foo",
                path=["bar", "bar2"],
                instance="i1"),
            exceptions.ValidationError(
                "2",
                validator="quux",
                path=["foobar", 2],
                instance="i2"),
        )
        # Will raise an exception if the bug is still there.
        exceptions.ErrorTree([e1, e2]) 
Example 65
Project: Requester   Author: kylebebak   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_does_not_contain_subtrees_that_are_not_in_the_instance(self):
        error = exceptions.ValidationError("123", validator="foo", instance=[])
        tree = exceptions.ErrorTree([error])

        with self.assertRaises(IndexError):
            tree[0] 
Example 66
Project: Requester   Author: kylebebak   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_if_its_in_the_tree_anyhow_it_does_not_raise_an_error(self):
        """
        If a validator is dumb (like :validator:`required` in draft 3) and
        refers to a path that isn't in the instance, the tree still properly
        returns a subtree for that path.

        """

        error = exceptions.ValidationError(
            "a message", validator="foo", instance={}, path=["foo"],
        )
        tree = exceptions.ErrorTree([error])
        self.assertIsInstance(tree["foo"], exceptions.ErrorTree) 
Example 67
Project: TA-securitytrails   Author: secops4thewin   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_knows_how_many_total_errors_it_contains(self):
        errors = [mock.MagicMock() for _ in range(8)]
        tree = exceptions.ErrorTree(errors)
        self.assertEqual(tree.total_errors, 8) 
Example 68
Project: TA-securitytrails   Author: secops4thewin   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_contains_an_item_if_the_item_had_an_error(self):
        errors = [exceptions.ValidationError("a message", path=["bar"])]
        tree = exceptions.ErrorTree(errors)
        self.assertIn("bar", tree) 
Example 69
Project: TA-securitytrails   Author: secops4thewin   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_does_not_contain_an_item_if_the_item_had_no_error(self):
        errors = [exceptions.ValidationError("a message", path=["bar"])]
        tree = exceptions.ErrorTree(errors)
        self.assertNotIn("foo", tree) 
Example 70
Project: TA-securitytrails   Author: secops4thewin   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_validators_that_failed_appear_in_errors_dict(self):
        error = exceptions.ValidationError("a message", validator="foo")
        tree = exceptions.ErrorTree([error])
        self.assertEqual(tree.errors, {"foo" : error}) 
Example 71
Project: TA-securitytrails   Author: secops4thewin   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_creates_a_child_tree_for_each_nested_path(self):
        errors = [
            exceptions.ValidationError("a bar message", path=["bar"]),
            exceptions.ValidationError("a bar -> 0 message", path=["bar", 0]),
        ]
        tree = exceptions.ErrorTree(errors)
        self.assertIn(0, tree["bar"])
        self.assertNotIn(1, tree["bar"]) 
Example 72
Project: TA-securitytrails   Author: secops4thewin   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_does_not_contain_subtrees_that_are_not_in_the_instance(self):
        error = exceptions.ValidationError("123", validator="foo", instance=[])
        tree = exceptions.ErrorTree([error])

        with self.assertRaises(IndexError):
            tree[0] 
Example 73
Project: TA-securitytrails   Author: secops4thewin   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_if_its_in_the_tree_anyhow_it_does_not_raise_an_error(self):
        """
        If a validator is dumb (like :validator:`required` in draft 3) and
        refers to a path that isn't in the instance, the tree still properly
        returns a subtree for that path.

        """

        error = exceptions.ValidationError(
            "a message", validator="foo", instance={}, path=["foo"],
        )
        tree = exceptions.ErrorTree([error])
        self.assertIsInstance(tree["foo"], exceptions.ErrorTree) 
Example 74
Project: Pizza-or-Not-a-Pizza   Author: mraza007   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_knows_how_many_total_errors_it_contains(self):
        errors = [mock.MagicMock() for _ in range(8)]
        tree = exceptions.ErrorTree(errors)
        self.assertEqual(tree.total_errors, 8) 
Example 75
Project: Pizza-or-Not-a-Pizza   Author: mraza007   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_contains_an_item_if_the_item_had_an_error(self):
        errors = [exceptions.ValidationError("a message", path=["bar"])]
        tree = exceptions.ErrorTree(errors)
        self.assertIn("bar", tree) 
Example 76
Project: Pizza-or-Not-a-Pizza   Author: mraza007   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_does_not_contain_an_item_if_the_item_had_no_error(self):
        errors = [exceptions.ValidationError("a message", path=["bar"])]
        tree = exceptions.ErrorTree(errors)
        self.assertNotIn("foo", tree) 
Example 77
Project: Pizza-or-Not-a-Pizza   Author: mraza007   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_validators_that_failed_appear_in_errors_dict(self):
        error = exceptions.ValidationError("a message", validator="foo")
        tree = exceptions.ErrorTree([error])
        self.assertEqual(tree.errors, {"foo" : error}) 
Example 78
Project: Pizza-or-Not-a-Pizza   Author: mraza007   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_creates_a_child_tree_for_each_nested_path(self):
        errors = [
            exceptions.ValidationError("a bar message", path=["bar"]),
            exceptions.ValidationError("a bar -> 0 message", path=["bar", 0]),
        ]
        tree = exceptions.ErrorTree(errors)
        self.assertIn(0, tree["bar"])
        self.assertNotIn(1, tree["bar"]) 
Example 79
Project: Pizza-or-Not-a-Pizza   Author: mraza007   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_it_does_not_contain_subtrees_that_are_not_in_the_instance(self):
        error = exceptions.ValidationError("123", validator="foo", instance=[])
        tree = exceptions.ErrorTree([error])

        with self.assertRaises(IndexError):
            tree[0] 
Example 80
Project: Pizza-or-Not-a-Pizza   Author: mraza007   File: test_exceptions.py    MIT License 5 votes vote down vote up
def test_if_its_in_the_tree_anyhow_it_does_not_raise_an_error(self):
        """
        If a validator is dumb (like :validator:`required` in draft 3) and
        refers to a path that isn't in the instance, the tree still properly
        returns a subtree for that path.

        """

        error = exceptions.ValidationError(
            "a message", validator="foo", instance={}, path=["foo"],
        )
        tree = exceptions.ErrorTree([error])
        self.assertIsInstance(tree["foo"], exceptions.ErrorTree)