Python jsonschema.validators.Draft4Validator() Examples
The following are 13
code examples of jsonschema.validators.Draft4Validator().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
jsonschema.validators
, or try the search function
.
Example #1
Source File: test_format.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_format_error_causes_become_validation_error_causes(self): checker = FormatChecker() checker.checks("foo", raises=ValueError)(self.fn) cause = self.fn.side_effect = ValueError() validator = Draft4Validator({"format": "foo"}, format_checker=checker) with self.assertRaises(ValidationError) as cm: validator.validate("bar") self.assertIs(cm.exception.__cause__, cause)
Example #2
Source File: test_format.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_format_error_causes_become_validation_error_causes(self): checker = FormatChecker() checker.checks("foo", raises=ValueError)(self.fn) cause = self.fn.side_effect = ValueError() validator = Draft4Validator({"format": "foo"}, format_checker=checker) with self.assertRaises(ValidationError) as cm: validator.validate("bar") self.assertIs(cm.exception.__cause__, cause)
Example #3
Source File: test_format.py From core with MIT License | 5 votes |
def test_format_error_causes_become_validation_error_causes(self): checker = FormatChecker() checker.checks("foo", raises=ValueError)(self.fn) cause = self.fn.side_effect = ValueError() validator = Draft4Validator({"format" : "foo"}, format_checker=checker) with self.assertRaises(ValidationError) as cm: validator.validate("bar") self.assertIs(cm.exception.__cause__, cause)
Example #4
Source File: test_format.py From deepWordBug with Apache License 2.0 | 5 votes |
def test_format_error_causes_become_validation_error_causes(self): checker = FormatChecker() checker.checks("foo", raises=ValueError)(self.fn) cause = self.fn.side_effect = ValueError() validator = Draft4Validator({"format": "foo"}, format_checker=checker) with self.assertRaises(ValidationError) as cm: validator.validate("bar") self.assertIs(cm.exception.__cause__, cause)
Example #5
Source File: validate.py From aiohttp_apiset with Apache License 2.0 | 5 votes |
def factory(cls, *args, **kwargs): factory = extend(Draft4Validator, dict(required=cls._required)) return factory(*args, format_checker=cls.format_checker, **kwargs)
Example #6
Source File: test_fictional_example.py From sample-data with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_valid(filename, schema): errors = 0 with open(filename) as f: data = json.load(f) for error in validator(schema, format_checker=FormatChecker()).iter_errors(data): errors += 1 warnings.warn(json.dumps(error.instance, indent=2, separators=(',', ': '))) warnings.warn('{} ({})\n'.format(error.message, '/'.join(error.absolute_schema_path))) assert errors == 0, '{} is invalid. See warnings below.'.format(filename)
Example #7
Source File: test_format.py From accelerated-data-lake with Apache License 2.0 | 5 votes |
def test_format_error_causes_become_validation_error_causes(self): checker = FormatChecker() checker.checks("foo", raises=ValueError)(self.fn) cause = self.fn.side_effect = ValueError() validator = Draft4Validator({"format": "foo"}, format_checker=checker) with self.assertRaises(ValidationError) as cm: validator.validate("bar") self.assertIs(cm.exception.__cause__, cause)
Example #8
Source File: test_format.py From Requester with MIT License | 5 votes |
def test_format_error_causes_become_validation_error_causes(self): checker = FormatChecker() checker.checks("foo", raises=ValueError)(self.fn) cause = self.fn.side_effect = ValueError() validator = Draft4Validator({"format": "foo"}, format_checker=checker) with self.assertRaises(ValidationError) as cm: validator.validate("bar") self.assertIs(cm.exception.__cause__, cause)
Example #9
Source File: test_compute.py From watcher with Apache License 2.0 | 5 votes |
def test_compute_schema(self): test_scope = fake_scopes.compute_scope validators.Draft4Validator( audit_template.AuditTemplatePostType._build_schema() ).validate(test_scope)
Example #10
Source File: test_format.py From SA-ctf_scoreboard with Creative Commons Zero v1.0 Universal | 5 votes |
def test_format_error_causes_become_validation_error_causes(self): checker = FormatChecker() checker.checks("foo", raises=ValueError)(self.fn) cause = self.fn.side_effect = ValueError() validator = Draft4Validator({"format" : "foo"}, format_checker=checker) with self.assertRaises(ValidationError) as cm: validator.validate("bar") self.assertIs(cm.exception.__cause__, cause)
Example #11
Source File: factories.py From openapi-spec-validator with Apache License 2.0 | 5 votes |
def from_resolver(cls, spec_resolver): """Creates a customized Draft4ExtendedValidator. :param spec_resolver: resolver for the spec :type resolver: :class:`jsonschema.RefResolver` """ spec_validators = cls._get_spec_validators(spec_resolver) return validators.extend(Draft4Validator, spec_validators)
Example #12
Source File: test_format.py From pyblish-qml with GNU Lesser General Public License v3.0 | 5 votes |
def test_format_error_causes_become_validation_error_causes(self): checker = FormatChecker() checker.checks("foo", raises=ValueError)(self.fn) cause = self.fn.side_effect = ValueError() validator = Draft4Validator({"format" : "foo"}, format_checker=checker) with self.assertRaises(ValidationError) as cm: validator.validate("bar") self.assertIs(cm.exception.__cause__, cause)
Example #13
Source File: __init__.py From jsonmerge with MIT License | 4 votes |
def __init__(self, schema, strategies=(), objclass_def='dict', objclass_menu=None, validatorclass=Draft4Validator): """Create a new Merger object. schema -- JSON schema to use when merging. strategies -- Any additional merge strategies to use during merge. objclass_def -- Name of the default class for JSON objects. objclass_menu -- Any additional classes for JSON objects. validatorclass -- JSON Schema validator class. strategies argument should be a dict mapping strategy names to instances of Strategy subclasses. objclass_def specifies the default class used for JSON objects when one is not specified in the schema. It should be 'dict' (dict built-in), 'OrderedDict' (collections.OrderedDict) or one of the names specified in the objclass_menu argument. If not specified, 'dict' is used. objclass_menu argument should be a dictionary that maps a string name to a function or class that will return an empty dictionary-like object to use as a JSON object. The function must accept either no arguments or a dictionary-like object. validatorclass argument can be used to supply a validator class from jsonschema. This can be used for example to specify which JSON Schema draft version will be used during merge. """ self.schema = schema if hasattr(validatorclass, 'ID_OF'): resolver = LocalRefResolver.from_schema(schema, id_of=validatorclass.ID_OF) else: # jsonschema<3.0.0 resolver = LocalRefResolver.from_schema(schema) self.validator = validatorclass(schema, resolver=resolver) self.strategies = dict(self.STRATEGIES) self.strategies.update(strategies) self.objclass_menu = { 'dict': dict, 'OrderedDict': OrderedDict } if objclass_menu: self.objclass_menu.update(objclass_menu) self.objclass_menu['_default'] = self.objclass_menu[objclass_def]