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: pv.validate({}, schema) chk_schema.assert_called_once_with({}, schema)
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: 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: pv.validate({}, schema) chk_schema.assert_called_once_with({}, schema)
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 self.assertRaisesRegex(ValidationError, r"\[1, 2, 3\] is not of type u?'object'"): pv.validate([1, 2, 3])
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])
def test_draft4_validator_is_the_default(self): pv = PandelVisitor({}) with mock.patch.object(pv, "iter_errors", return_value=()) as chk_schema: pv.validate({}, {}) chk_schema.assert_called_once_with({}, {})
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]}))
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]}))
def test_rule_additionalProperties_for_pandas(self): schema = { "type": ["object"], "additionalProperties": False, "properties": { "foo": {} }, } pv = PandelVisitor(schema) pv.validate({"foo": 1}) with self.assertRaisesRegex( ValidationError, r"Additional properties are not allowed \(u?'bar' was unexpected\)", ): pv.validate({"foo": 1, "bar": 2}) pv.validate(pd.Series({"foo": 1})) with self.assertRaisesRegex( ValidationError, r"Additional properties are not allowed \(u?'bar' was unexpected\)", ): pv.validate(pd.Series({"foo": 1, "bar": 2})) pv.validate(pd.DataFrame({"foo": [1]})) with self.assertRaisesRegex( ValidationError, r"Additional properties are not allowed \(u?'bar' was unexpected\)", ): pv.validate(pd.DataFrame({"foo": [1], "bar": [2]}))
def test_rule_requiredProperties_rule_for_pandas(self): schema = {"type": ["object"], "required": ["foo"]} pv = PandelVisitor(schema) pv.validate({"foo": "bar"}) with self.assertRaisesRegex(ValidationError, "'foo' is a required property"): pv.validate({"foofoo": "bar"}) pv.validate(pd.Series({"foo": "bar", "foofoo": "bar"})) with self.assertRaisesRegex(ValidationError, "'foo' is a required property"): pv.validate(pd.Series({"foofoo": "bar"})) pv.validate(pd.DataFrame({"foo": [1, 2], "foofoo": [3, 4]})) with self.assertRaisesRegex(ValidationError, "'foo' is a required property"): pv.validate(pd.DataFrame({"foofoo": [1, 2], "bar": [3, 4]}))