Пример #1
0
 def test_draft4_validator_is_the_default(self):
     pv = PandelVisitor({})
     with mock.patch.object(
             pv, "iter_errors",
             return_value=()) as chk_schema:  # @UndefinedVariable
         pv.validate({}, {})
         chk_schema.assert_called_once_with({}, {})
Пример #2
0
 def test_draft4_validator_is_chosen(self):
     pv = PandelVisitor({})
     schema = {"$schema": "http://json-schema.org/draft-04/schema#"}
     with mock.patch.object(
             pv, "iter_errors",
             return_value=()) as chk_schema:  # @UndefinedVariable
         pv.validate({}, schema)
         chk_schema.assert_called_once_with({}, schema)
Пример #3
0
    def test_draft3_validator_is_chosen(self):
        pv = PandelVisitor({})
        schema = {"$schema" : "http://json-schema.org/draft-03/schema#"}
        with mock.patch.object(pv, "iter_errors", return_value=()) as chk_schema:      # @UndefinedVariable
            pv.validate({}, schema)
            chk_schema.assert_called_once_with({}, schema)

        # Make sure it works without the empty fragment
        pv = PandelVisitor({})
        schema = {"$schema" : "http://json-schema.org/draft-03/schema"}
        with mock.patch.object(pv, "iter_errors", return_value=()) as chk_schema:      # @UndefinedVariable
            pv.validate({}, schema)
            chk_schema.assert_called_once_with({}, schema)
Пример #4
0
    def test_validate_object_or_pandas(self):
        schema = {
            'type': ['object'],
        }
        pv = PandelVisitor(schema)

        pv.validate({'foo': 'bar'})
        pv.validate(pd.Series({'foo': 'bar', 'foofoo': 'bar'}))
        pv.validate(pd.DataFrame({'foo': [1,2], 'foofoo': [3,4]}))

        with assertRaisesRegex(self, ValidationError, "\[1, 2, 3\] is not of type u?'object'"):
            pv.validate([1,2,3])
Пример #5
0
    def test_validate_object_or_pandas(self):
        schema = {
            'type': ['object'],
        }
        pv = PandelVisitor(schema)

        pv.validate({'foo': 'bar'})
        pv.validate(pd.Series({'foo': 'bar', 'foofoo': 'bar'}))
        pv.validate(pd.DataFrame({'foo': [1, 2], 'foofoo': [3, 4]}))

        with assertRaisesRegex(self, ValidationError,
                               "\[1, 2, 3\] is not of type u?'object'"):
            pv.validate([1, 2, 3])
Пример #6
0
    def test_rule_additionalProperties_for_pandas(self):
        schema = {
            'type': ['object'],
            'additionalProperties': False,
            'properties': {
                'foo': {},
            }
        }
        pv = PandelVisitor(schema)

        pv.validate({'foo': 1})
        with assertRaisesRegex(
                self, ValidationError,
                "Additional properties are not allowed \(u?'bar' was unexpected\)"
        ):
            pv.validate({'foo': 1, 'bar': 2})

        pv.validate(pd.Series({'foo': 1}))
        with assertRaisesRegex(
                self, ValidationError,
                "Additional properties are not allowed \(u?'bar' was unexpected\)"
        ):
            pv.validate(pd.Series({'foo': 1, 'bar': 2}))

        pv.validate(pd.DataFrame({'foo': [1]}))
        with assertRaisesRegex(
                self, ValidationError,
                "Additional properties are not allowed \(u?'bar' was unexpected\)"
        ):
            pv.validate(pd.DataFrame({'foo': [1], 'bar': [2]}))
Пример #7
0
    def test_rule_requiredProperties_rule_for_pandas(self):
        schema = {'type': ['object'], 'required': ['foo']}
        pv = PandelVisitor(schema)

        pv.validate({'foo': 'bar'})
        with assertRaisesRegex(self, ValidationError,
                               "'foo' is a required property"):
            pv.validate({'foofoo': 'bar'})

        pv.validate(pd.Series({'foo': 'bar', 'foofoo': 'bar'}))
        with assertRaisesRegex(self, ValidationError,
                               "'foo' is a required property"):
            pv.validate(pd.Series({'foofoo': 'bar'}))

        pv.validate(pd.DataFrame({'foo': [1, 2], 'foofoo': [3, 4]}))
        with assertRaisesRegex(self, ValidationError,
                               "'foo' is a required property"):
            pv.validate(pd.DataFrame({'foofoo': [1, 2], 'bar': [3, 4]}))
Пример #8
0
 def test_draft4_validator_is_the_default(self):
     pv = PandelVisitor({})
     with mock.patch.object(pv, "iter_errors", return_value=()) as chk_schema:      # @UndefinedVariable
         pv.validate({}, {})
         chk_schema.assert_called_once_with({}, {})
Пример #9
0
    def test_rule_additionalProperties_for_pandas(self):
        schema = {
            'type': ['object'],
            'additionalProperties': False,
            'properties': {
                'foo': {},
            }
        }
        pv = PandelVisitor(schema)

        pv.validate({'foo': 1})
        with assertRaisesRegex(self, ValidationError, "Additional properties are not allowed \(u?'bar' was unexpected\)"):
            pv.validate({'foo': 1, 'bar': 2})

        pv.validate(pd.Series({'foo': 1}))
        with assertRaisesRegex(self, ValidationError, "Additional properties are not allowed \(u?'bar' was unexpected\)"):
            pv.validate(pd.Series({'foo': 1, 'bar': 2}))

        pv.validate(pd.DataFrame({'foo': [1]}))
        with assertRaisesRegex(self, ValidationError, "Additional properties are not allowed \(u?'bar' was unexpected\)"):
            pv.validate(pd.DataFrame({'foo': [1], 'bar': [2]}))
Пример #10
0
    def test_rule_requiredProperties_rule_for_pandas(self):
        schema = {
            'type': ['object'],
            'required': ['foo']
        }
        pv = PandelVisitor(schema)

        pv.validate({'foo': 'bar'})
        with assertRaisesRegex(self, ValidationError, "'foo' is a required property"):
            pv.validate({'foofoo': 'bar'})

        pv.validate(pd.Series({'foo': 'bar', 'foofoo': 'bar'}))
        with assertRaisesRegex(self, ValidationError, "'foo' is a required property"):
            pv.validate(pd.Series({'foofoo': 'bar'}))

        pv.validate(pd.DataFrame({'foo': [1,2], 'foofoo': [3,4]}))
        with assertRaisesRegex(self, ValidationError, "'foo' is a required property"):
            pv.validate(pd.DataFrame({'foofoo': [1,2], 'bar': [3,4]}))